Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from rubocop to standard #8

Merged
merged 7 commits into from
Dec 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

strategy:
matrix:
ruby: [3.3.0-preview1, 3.2.2, 3.1.4, 3.0.5, 2.7.7, 2.6.10, 2.5.9]
ruby: [3.3.0, 3.2.2, 3.1.4, 3.0.6]

name: CI Ruby ${{ matrix.ruby }}
steps:
Expand All @@ -26,18 +26,18 @@ jobs:
run: bundle install
- name: RSpec
run: bundle exec rspec
- name: Rubocop
run: bundle exec rubocop
- name: Standard
run: bundle exec standardrb
- name: Coveralls
if: ${{ matrix.ruby == '3.2.2' }}
if: ${{ matrix.ruby == '3.3.0' }}
continue-on-error: true
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Code Climate
if: ${{ matrix.ruby == '3.2.2' }}
if: ${{ matrix.ruby == '3.3.0' }}
continue-on-error: true
uses: paambaati/codeclimate-action@v4.0.0
uses: paambaati/codeclimate-action@v5.0.0
env:
CC_TEST_REPORTER_ID: ${{ secrets.CODE_CLIMATE_TOKEN }}
with:
Expand Down
24 changes: 0 additions & 24 deletions .rubocop.yml

This file was deleted.

18 changes: 0 additions & 18 deletions .ruby-style.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .standard-rspec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require:
- rubocop-rspec
7 changes: 7 additions & 0 deletions .standard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ruby_version: 3.0

plugins:
- standard-performance

extend_config:
- .standard-rspec.yml
10 changes: 7 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
*Unreleased*

* Ensure Rails 7.0 compability
* Ensure Ruby 3.1 compability
* Ensure Ruby 3.3 compability
* Ensure Rails 7.1 compability
* Ensure Ruby 3.2 compability
* Ensure Ruby 3.3.0-preview compability
* Ensure Ruby 3.1 compability
* Switch from Travis CI to GitHub Actions
* Switch from Rubocop to Standard
* Stop testing against Ruby 2.7
* Stop testing against Ruby 2.6
* Stop testing against Ruby 2.5

*5.0.1 (December 28, 2020)*

Expand Down
17 changes: 8 additions & 9 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
# frozen_string_literal: true

source 'https://rubygems.org'
source "https://rubygems.org"

gemspec

gem 'rake'
gem 'rspec'
gem 'rubocop'
gem 'rubocop-performance'
gem 'rubocop-rake'
gem 'rubocop-rspec'
gem 'simplecov'
gem 'simplecov-lcov'
gem "rake"
gem "rspec"
gem "rubocop-rspec"
gem "simplecov"
gem "simplecov-lcov"
gem "standard"
gem "standard-performance"
7 changes: 3 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# frozen_string_literal: true

require 'rspec/core/rake_task'
require 'rubocop/rake_task'
require "rspec/core/rake_task"
require "standard/rake"

RSpec::Core::RakeTask.new(:spec) do |t|
t.verbose = false
end
RuboCop::RakeTask.new(:rubocop)

task default: %i[spec rubocop]
task default: %i[spec standard]
30 changes: 15 additions & 15 deletions has_configuration.gemspec
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
# frozen_string_literal: true

lib = File.expand_path('lib', __dir__)
lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

require 'version'
require "version"

Gem::Specification.new do |spec|
spec.authors = ['Martin Spickermann']
spec.email = ['[email protected]']
spec.homepage = 'https://github.com/spickermann/has_configuration'
spec.license = 'MIT'
spec.authors = ["Martin Spickermann"]
spec.email = ["[email protected]"]
spec.homepage = "https://github.com/spickermann/has_configuration"
spec.license = "MIT"

spec.name = 'has_configuration'
spec.version = HasConfiguration::VERSION::STRING
spec.name = "has_configuration"
spec.version = HasConfiguration::VERSION::STRING

spec.summary = 'Simple configuration handling'
spec.description = <<-DESCRIPTION
spec.summary = "Simple configuration handling"
spec.description = <<-DESCRIPTION
Loads configuration setting from a yml file and adds a configuation method
to class and instances
DESCRIPTION

spec.files = Dir['CHANGELOG', 'MIT-LICENSE', 'README', 'lib/**/*', 'spec/**/*']
spec.files = Dir["CHANGELOG", "MIT-LICENSE", "README", "lib/**/*", "spec/**/*"]

spec.require_path = ['lib']
spec.require_path = ["lib"]

spec.required_ruby_version = '>= 2.5.0'
spec.required_ruby_version = ">= 3.0.0"

spec.add_dependency('activesupport', '>= 4.2.2')
spec.add_dependency("activesupport", ">= 6.1.0")

spec.metadata['rubygems_mfa_required'] = 'true'
spec.metadata["rubygems_mfa_required"] = "true"
end
2 changes: 1 addition & 1 deletion lib/has_configuration.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require 'has_configuration/configuration'
require "has_configuration/configuration"

module HasConfiguration # :nodoc:
def self.included(base)
Expand Down
37 changes: 14 additions & 23 deletions lib/has_configuration/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,48 +1,39 @@
# frozen_string_literal: true

require 'active_support/core_ext/hash/indifferent_access'
require 'ostruct'
require 'yaml'
require "active_support/core_ext/hash/indifferent_access"
require "ostruct"
require "yaml"

module HasConfiguration # :nodoc:
class Configuration # :nodoc:
def initialize(klass, options = {})
@class_name = klass.name
@options = options
@options = options

load_file
init_hash
end

def to_h(type = nil)
case type
when :symbolized then deep_symbolized_hash
when :stringify then deep_stringified_hash
else @hash
when :symbolized then deep_symbolized_hash
when :stringify then deep_stringified_hash
else @hash
end
end

private

def method_missing(sym, *args, &block)
configuration.send(sym, *args, &block) || super
def method_missing(sym, ...)
configuration.send(sym, ...) || super
end

def respond_to_missing?(sym, include_private = false)
configuration.respond_to?(sym, include_private)
end

def load_file
@raw = if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.6.0')
YAML.safe_load(ERB.new(raw_file(filename)).result, aliases: true)
else
YAML.safe_load(
ERB.new(raw_file(filename)).result,
[], # whitelist_classes
[], # whitelist_symbols
true # allow aliases
)
end
@raw = YAML.safe_load(ERB.new(raw_file(filename)).result, aliases: true)
end

def init_hash
Expand All @@ -62,26 +53,26 @@ def filename
@options[:file] || determine_filename_from_class ||
raise(
ArgumentError,
'Unable to resolve filename, please add :file parameter to has_configuration'
"Unable to resolve filename, please add :file parameter to has_configuration"
)
end

def determine_filename_from_class
return unless @class_name

filename = "#{@class_name.downcase}.yml"
defined?(Rails) ? Rails.root.join('config', filename).to_s : filename
defined?(Rails) ? Rails.root.join("config", filename).to_s : filename
end

def environment
return @options[:env] if @options.key?(:env)
return Rails.env.to_s if defined?(Rails)
Rails.env.to_s if defined?(Rails)
end

def deep_structify(hash)
hash ||= {}
result = hash.transform_values { |v| v.is_a?(Hash) ? deep_structify(v) : v }
OpenStruct.new(result) # rubocop:disable Style/OpenStructUse
OpenStruct.new(result)
end

def deep_symbolized_hash
Expand Down
2 changes: 1 addition & 1 deletion lib/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ module VERSION # :nodoc:
MINOR = 0
BUILD = 1

STRING = [MAJOR, MINOR, BUILD].join('.')
STRING = [MAJOR, MINOR, BUILD].join(".")
end
end
Loading