has_configuration 5.0.1 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9ef13678ebcf0232c7c0b7535487a70b25d0e245686ca4acb7a8683cbee59d4a
4
- data.tar.gz: '04568b62a1c1259c4e14dca63438e3ac60032f1ca78e103a0c09f0d8d816b14f'
3
+ metadata.gz: 9900b392e98d9a9cea21c03c580ac9401b6967908a6daf653b338d0be95bbe5a
4
+ data.tar.gz: 75276e32b7167ff2097713cc8552705063dc8037034f5adb5b6dbbdf0152691c
5
5
  SHA512:
6
- metadata.gz: ad96fe37a596f768234729a99597a4429d1893b4765ba6196e3f904f038e021b4a5395927ae58a5f0d4a102568d0cbe663b4d85bd0d675563881e1bdb6b1cac6
7
- data.tar.gz: 12f7267b2de11e3c0fe91b77e222281cf6dafc010f6d817358cd78ac936f5457612535a995b2bffde62efd65923bc105f4d7e33ad2a96d3347ee2e59d7a0710a
6
+ metadata.gz: 2b5c225aaaacbfa20315db359c063c19866535538021e252e9737186cae252cee47352ba2893b9782aa002666aea856cbc21cbabc4bc61cadd31525820b5c64c
7
+ data.tar.gz: 37bb26491f37b7fc5d4f8d4053739d0cdf526fa3b73ffcc70a248d87b58104e25175acb71fea408a8a9c534f261dabfd11e22e5e1e1720bdc8f42ffb11585d33
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_support/core_ext/hash/indifferent_access'
4
- require 'ostruct'
5
- require 'yaml'
3
+ require "active_support/core_ext/hash/indifferent_access"
4
+ require "ostruct"
5
+ require "yaml"
6
6
 
7
- module HasConfiguration #:nodoc:
8
- class Configuration #:nodoc:
7
+ module HasConfiguration # :nodoc:
8
+ class Configuration # :nodoc:
9
9
  def initialize(klass, options = {})
10
10
  @class_name = klass.name
11
- @options = options
11
+ @options = options
12
12
 
13
13
  load_file
14
14
  init_hash
@@ -16,16 +16,16 @@ module HasConfiguration #:nodoc:
16
16
 
17
17
  def to_h(type = nil)
18
18
  case type
19
- when :symbolized then deep_symbolized_hash
20
- when :stringify then deep_stringified_hash
21
- else @hash
19
+ when :symbolized then deep_symbolized_hash
20
+ when :stringify then deep_stringified_hash
21
+ else @hash
22
22
  end
23
23
  end
24
24
 
25
25
  private
26
26
 
27
- def method_missing(sym, *args, &block)
28
- configuration.send(sym, *args, &block) || super
27
+ def method_missing(sym, ...)
28
+ configuration.send(sym, ...) || super
29
29
  end
30
30
 
31
31
  def respond_to_missing?(sym, include_private = false)
@@ -33,16 +33,7 @@ module HasConfiguration #:nodoc:
33
33
  end
34
34
 
35
35
  def load_file
36
- @raw = if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.6.0')
37
- YAML.safe_load(ERB.new(raw_file(filename)).result, aliases: true)
38
- else
39
- YAML.safe_load(
40
- ERB.new(raw_file(filename)).result,
41
- [], # whitelist_classes
42
- [], # whitelist_symbols
43
- true # allow aliases
44
- )
45
- end
36
+ @raw = YAML.safe_load(ERB.new(raw_file(filename)).result, aliases: true)
46
37
  end
47
38
 
48
39
  def init_hash
@@ -62,7 +53,7 @@ module HasConfiguration #:nodoc:
62
53
  @options[:file] || determine_filename_from_class ||
63
54
  raise(
64
55
  ArgumentError,
65
- 'Unable to resolve filename, please add :file parameter to has_configuration'
56
+ "Unable to resolve filename, please add :file parameter to has_configuration"
66
57
  )
67
58
  end
68
59
 
@@ -70,12 +61,12 @@ module HasConfiguration #:nodoc:
70
61
  return unless @class_name
71
62
 
72
63
  filename = "#{@class_name.downcase}.yml"
73
- defined?(Rails) ? Rails.root.join('config', filename).to_s : filename
64
+ defined?(Rails) ? Rails.root.join("config", filename).to_s : filename
74
65
  end
75
66
 
76
67
  def environment
77
68
  return @options[:env] if @options.key?(:env)
78
- return Rails.env.to_s if defined?(Rails)
69
+ Rails.env.to_s if defined?(Rails)
79
70
  end
80
71
 
81
72
  def deep_structify(hash)
@@ -1,13 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'has_configuration/configuration'
3
+ require "has_configuration/configuration"
4
4
 
5
- module HasConfiguration #:nodoc:
5
+ module HasConfiguration # :nodoc:
6
6
  def self.included(base)
7
7
  base.extend(ClassMethods)
8
8
  end
9
9
 
10
- module ClassMethods #:nodoc:
10
+ module ClassMethods # :nodoc:
11
11
  # Load configuration settings from a yaml file and adds a class and an instance
12
12
  # method +configuration+ to the object.
13
13
  #
@@ -82,7 +82,7 @@ module HasConfiguration #:nodoc:
82
82
  base.extend(ClassMethods)
83
83
  end
84
84
 
85
- module ClassMethods #:nodoc:
85
+ module ClassMethods # :nodoc:
86
86
  attr_reader :configuration
87
87
  end
88
88
 
@@ -93,6 +93,6 @@ module HasConfiguration #:nodoc:
93
93
  end
94
94
  end
95
95
 
96
- class Object #:nodoc:
96
+ class Object # :nodoc:
97
97
  include HasConfiguration
98
98
  end
data/lib/version.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module HasConfiguration #:nodoc:
4
- module VERSION #:nodoc:
5
- MAJOR = 5
3
+ module HasConfiguration # :nodoc:
4
+ module VERSION # :nodoc:
5
+ MAJOR = 6
6
6
  MINOR = 0
7
- BUILD = 1
7
+ BUILD = 0
8
8
 
9
- STRING = [MAJOR, MINOR, BUILD].join('.')
9
+ STRING = [MAJOR, MINOR, BUILD].join(".")
10
10
  end
11
11
  end
@@ -1,117 +1,117 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'has_configuration'
3
+ require "has_configuration"
4
4
 
5
- require 'support/rails_mock'
5
+ require "support/rails_mock"
6
6
 
7
7
  RSpec.describe HasConfiguration::Configuration do
8
8
  let(:klass) { Class }
9
9
 
10
10
  before do
11
- allow_any_instance_of( # rubocop:disable RSpec/AnyInstance
11
+ allow_any_instance_of( # standard:disable RSpec/AnyInstance
12
12
  Configuration
13
13
  ).to receive(:raw_file).and_return(File.read(fixture))
14
14
  end
15
15
 
16
- describe '.new' do
17
- let(:fixture) { 'spec/fixtures/class.yml' }
16
+ describe ".new" do
17
+ let(:fixture) { "spec/fixtures/class.yml" }
18
18
 
19
- context 'when no filename provided' do
20
- let(:file) { '/RAILS_ROOT/config/class.yml' }
19
+ context "when no filename provided" do
20
+ let(:file) { "/RAILS_ROOT/config/class.yml" }
21
21
 
22
- it 'loads default file' do
22
+ it "loads default file" do
23
23
  configuration = described_class.new(klass)
24
24
  expect(configuration).to have_received(:raw_file).with(file)
25
25
  end
26
26
  end
27
27
 
28
- context 'when filename provided' do
29
- let(:file) { 'foo/bar.yml' }
28
+ context "when filename provided" do
29
+ let(:file) { "foo/bar.yml" }
30
30
 
31
- it 'loads provided file' do
31
+ it "loads provided file" do
32
32
  configuration = described_class.new(klass, file: file)
33
33
  expect(configuration).to have_received(:raw_file).with(file)
34
34
  end
35
35
  end
36
36
  end
37
37
 
38
- context 'when initialized' do
38
+ context "when initialized" do
39
39
  let(:environment) { nil }
40
40
 
41
- context 'without env option' do
41
+ context "without env option" do
42
42
  subject(:hash) { described_class.new(klass).to_h }
43
43
 
44
- let(:fixture) { 'spec/fixtures/class.yml' }
44
+ let(:fixture) { "spec/fixtures/class.yml" }
45
45
 
46
- it 'return the expected hash' do
47
- expect(hash).to eq('env' => 'test')
46
+ it "return the expected hash" do
47
+ expect(hash).to eq("env" => "test")
48
48
  end
49
49
  end
50
50
 
51
- context 'with env option' do
51
+ context "with env option" do
52
52
  subject(:hash) { described_class.new(klass, env: environment).to_h }
53
53
 
54
- let(:environment) { 'production' }
55
- let(:fixture) { 'spec/fixtures/class.yml' }
54
+ let(:environment) { "production" }
55
+ let(:fixture) { "spec/fixtures/class.yml" }
56
56
 
57
- it 'return the expected hash' do
58
- expect(hash).to eq('env' => environment)
57
+ it "return the expected hash" do
58
+ expect(hash).to eq("env" => environment)
59
59
  end
60
60
  end
61
61
 
62
- context 'with yaml defaults' do
62
+ context "with yaml defaults" do
63
63
  subject(:hash) { described_class.new(klass).to_h }
64
64
 
65
- let(:fixture) { 'spec/fixtures/with_defaults.yml' }
65
+ let(:fixture) { "spec/fixtures/with_defaults.yml" }
66
66
 
67
- it 'return the expected hash' do
68
- expect(hash).to eq('default' => 'default', 'env' => 'test')
67
+ it "return the expected hash" do
68
+ expect(hash).to eq("default" => "default", "env" => "test")
69
69
  end
70
70
  end
71
71
 
72
- context 'with erb' do
72
+ context "with erb" do
73
73
  subject(:hash) { described_class.new(klass).to_h }
74
74
 
75
- let(:fixture) { 'spec/fixtures/with_erb.yml' }
75
+ let(:fixture) { "spec/fixtures/with_erb.yml" }
76
76
 
77
- it 'return the expected hash' do
78
- expect(hash).to eq('erb' => Rails.env)
77
+ it "return the expected hash" do
78
+ expect(hash).to eq("erb" => Rails.env)
79
79
  end
80
80
  end
81
81
  end
82
82
 
83
- describe '#to_h' do
84
- let(:fixture) { 'spec/fixtures/with_nested_attributes.yml' }
83
+ describe "#to_h" do
84
+ let(:fixture) { "spec/fixtures/with_nested_attributes.yml" }
85
85
 
86
- context 'without arguments' do
86
+ context "without arguments" do
87
87
  subject { described_class.new(klass).to_h }
88
88
 
89
89
  it { is_expected.to be_a(HashWithIndifferentAccess) }
90
90
  end
91
91
 
92
- context 'with :stringify' do
92
+ context "with :stringify" do
93
93
  subject { described_class.new(klass).to_h(:stringify) }
94
94
 
95
- it { is_expected.to eq('env' => 'test', 'nested' => { 'foo' => 'bar', 'baz' => true }) }
95
+ it { is_expected.to eq("env" => "test", "nested" => {"foo" => "bar", "baz" => true}) }
96
96
  end
97
97
 
98
- context 'with :symbolized' do
98
+ context "with :symbolized" do
99
99
  subject { described_class.new(klass).to_h(:symbolized) }
100
100
 
101
- it { is_expected.to eq(env: 'test', nested: { foo: 'bar', baz: true }) }
101
+ it { is_expected.to eq(env: "test", nested: {foo: "bar", baz: true}) }
102
102
  end
103
103
  end
104
104
 
105
- describe 'struct methods' do
105
+ describe "struct methods" do
106
106
  let(:configuration) { described_class.new(klass) }
107
- let(:fixture) { 'spec/fixtures/with_nested_attributes.yml' }
107
+ let(:fixture) { "spec/fixtures/with_nested_attributes.yml" }
108
108
 
109
- it 'supports multiple getter variants' do # rubocop:disable RSpec/MultipleExpectations
110
- expect(configuration.to_h[:env]).to eql('test')
111
- expect(configuration.env).to eql('test')
109
+ it "supports multiple getter variants" do # standard:disable RSpec/MultipleExpectations
110
+ expect(configuration.to_h[:env]).to eql("test")
111
+ expect(configuration.env).to eql("test")
112
112
 
113
- expect(configuration.to_h[:nested]['foo']).to eql('bar')
114
- expect(configuration.nested.foo).to eql('bar')
113
+ expect(configuration.to_h[:nested]["foo"]).to eql("bar")
114
+ expect(configuration.nested.foo).to eql("bar")
115
115
  end
116
116
  end
117
117
  end
@@ -1,29 +1,29 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Dummy
4
- require 'has_configuration'
5
- has_configuration file: 'spec/fixtures/class.yml'
4
+ require "has_configuration"
5
+ has_configuration file: "spec/fixtures/class.yml"
6
6
  end
7
7
 
8
8
  RSpec.describe HasConfiguration do
9
- context 'when declared' do
10
- context 'with a class' do
9
+ context "when declared" do
10
+ context "with a class" do
11
11
  subject(:dummy) { Dummy }
12
12
 
13
13
  it { is_expected.to respond_to(:configuration) }
14
14
 
15
- it 'returns a configuration' do
16
- expect(dummy.configuration).to be_present
15
+ it "returns a configuration" do
16
+ expect(dummy.configuration).to be_a HasConfiguration::Configuration
17
17
  end
18
18
  end
19
19
 
20
- context 'with an instance' do
20
+ context "with an instance" do
21
21
  subject(:dummy) { Dummy.new }
22
22
 
23
23
  it { is_expected.to respond_to(:configuration) }
24
24
 
25
- it 'returns a configuration' do
26
- expect(dummy.configuration).to be_present
25
+ it "returns a configuration" do
26
+ expect(dummy.configuration).to be_a HasConfiguration::Configuration
27
27
  end
28
28
  end
29
29
  end
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'coveralls'
4
- Coveralls.wear!
3
+ require "simplecov"
4
+
5
+ SimpleCov.start do
6
+ if ENV["CI"]
7
+ require "simplecov_json_formatter"
8
+ require "simplecov-lcov"
9
+
10
+ SimpleCov::Formatter::LcovFormatter.config do |c|
11
+ c.report_with_single_file = true
12
+ c.single_report_path = "coverage/lcov.info"
13
+ end
14
+
15
+ formatter SimpleCov::Formatter::MultiFormatter.new [
16
+ SimpleCov::Formatter::JSONFormatter, SimpleCov::Formatter::LcovFormatter
17
+ ]
18
+ end
19
+
20
+ add_filter %w[version.rb initializer.rb]
21
+ end
5
22
 
6
23
  # This file was generated by the `rspec --init` command. Conventionally, all
7
24
  # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
@@ -83,7 +100,7 @@ RSpec.configure do |config|
83
100
  # Use the documentation formatter for detailed output,
84
101
  # unless a formatter has already been configured
85
102
  # (e.g. via a command-line flag).
86
- config.default_formatter = 'doc'
103
+ config.default_formatter = "doc"
87
104
  end
88
105
 
89
106
  # Print the 10 slowest examples and example groups at the
@@ -3,10 +3,10 @@
3
3
  # Mocks Rails Environment
4
4
  Rails = Class.new do
5
5
  def self.root
6
- Pathname.new('/RAILS_ROOT')
6
+ Pathname.new("/RAILS_ROOT")
7
7
  end
8
8
 
9
9
  def self.env
10
- 'test'
10
+ "test"
11
11
  end
12
12
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_configuration
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.1
4
+ version: 6.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Spickermann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-28 00:00:00.000000000 Z
11
+ date: 2023-12-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,98 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 4.2.2
19
+ version: 6.1.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 4.2.2
27
- - !ruby/object:Gem::Dependency
28
- name: coveralls
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: rake
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: rspec
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: rubocop
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
- - !ruby/object:Gem::Dependency
84
- name: rubocop-performance
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
- - !ruby/object:Gem::Dependency
98
- name: rubocop-rspec
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: '0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - ">="
109
- - !ruby/object:Gem::Version
110
- version: '0'
26
+ version: 6.1.0
111
27
  description: |2
112
28
  Loads configuration setting from a yml file and adds a configuation method
113
29
  to class and instances
@@ -132,7 +48,8 @@ files:
132
48
  homepage: https://github.com/spickermann/has_configuration
133
49
  licenses:
134
50
  - MIT
135
- metadata: {}
51
+ metadata:
52
+ rubygems_mfa_required: 'true'
136
53
  post_install_message:
137
54
  rdoc_options: []
138
55
  require_paths:
@@ -141,14 +58,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
141
58
  requirements:
142
59
  - - ">="
143
60
  - !ruby/object:Gem::Version
144
- version: 2.5.0
61
+ version: 3.0.0
145
62
  required_rubygems_version: !ruby/object:Gem::Requirement
146
63
  requirements:
147
64
  - - ">="
148
65
  - !ruby/object:Gem::Version
149
66
  version: '0'
150
67
  requirements: []
151
- rubygems_version: 3.2.3
68
+ rubygems_version: 3.5.3
152
69
  signing_key:
153
70
  specification_version: 4
154
71
  summary: Simple configuration handling