has_configuration 3.0.0 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d6871b976889ba1ea377fbbf55f82fb08403a6f62cdbe9fff33a91e7926488e3
4
- data.tar.gz: 17211a4e0791bab7b86da28954df9566edf5d02fdf7a711540211a3a608af1eb
3
+ metadata.gz: 434cfdd0e94cbe7c1a355fbe98c4ba7ed644a531f788312005274a5dd4329fd8
4
+ data.tar.gz: d5fc4f5af682a4269a891b78d288a4c8215e5955d9e054868cf52ca2176a82db
5
5
  SHA512:
6
- metadata.gz: 206e30a3690d3ae732be32455725da21f26d175df81cc5d42259ae3b41223d7b59a2ad01d455ad016a262d4bc08bf7e23a531cd6371b573453a360cd457259e1
7
- data.tar.gz: 1dad8056157f26e4462ee98176361b68ce5e994a6e5afbb9e8e5c6983c8dd00962b6e4a2684f0c0dfe3bb8fd972be20d7b9f4ab6f1a104f4e440bf074339fa72
6
+ metadata.gz: 6c3fc02339bb8477a1c87a221978f20075ed7bc58eb29ff7303cf170a766be94ed40f2b3be7897d4d688df19d002e211ca495d10ce98ffe63957098419d1fb18
7
+ data.tar.gz: 2fd3655341039fa4d68848864c09d09077275bdde19b1aea54e68029e9106802ef8ebd0f96f53a38108ab656f8ebe05ca37e6d32c50a36104631bdd2c4d53b0e
@@ -31,12 +31,16 @@ module HasConfiguration #:nodoc:
31
31
  end
32
32
 
33
33
  def load_file
34
- @raw = YAML.safe_load(
35
- ERB.new(raw_file(filename)).result,
36
- [], # whitelist_classes
37
- [], # whitelist_symbols
38
- true # allow aliases
39
- )
34
+ @raw = if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.6.0')
35
+ YAML.safe_load(ERB.new(raw_file(filename)).result, aliases: true)
36
+ else
37
+ YAML.safe_load(
38
+ ERB.new(raw_file(filename)).result,
39
+ [], # whitelist_classes
40
+ [], # whitelist_symbols
41
+ true # allow aliases
42
+ )
43
+ end
40
44
  end
41
45
 
42
46
  def init_hash
@@ -65,7 +69,7 @@ module HasConfiguration #:nodoc:
65
69
  end
66
70
 
67
71
  def environment
68
- return @options[:env] if @options.keys.include?(:env)
72
+ return @options[:env] if @options.key?(:env)
69
73
  return Rails.env.to_s if defined?(Rails)
70
74
  end
71
75
 
@@ -71,7 +71,7 @@ module HasConfiguration #:nodoc:
71
71
  #
72
72
  def has_configuration(options = {})
73
73
  @configuration = Configuration.new(self, options)
74
- include Getter # rubocop:disable Style/MixinUsage
74
+ include Getter
75
75
  end
76
76
 
77
77
  # Adds getters for the configuration
data/lib/version.rb CHANGED
@@ -2,7 +2,7 @@ module HasConfiguration #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 3
4
4
  MINOR = 0
5
- BUILD = 0
5
+ BUILD = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, BUILD].join('.')
8
8
  end
@@ -6,7 +6,7 @@ RSpec.describe HasConfiguration::Configuration do
6
6
  let(:klass) { Class }
7
7
 
8
8
  before do
9
- allow_any_instance_of(
9
+ allow_any_instance_of( # rubocop:disable RSpec/AnyInstance
10
10
  Configuration
11
11
  ).to receive(:raw_file).and_return(File.read(fixture))
12
12
  end
@@ -18,8 +18,8 @@ RSpec.describe HasConfiguration::Configuration do
18
18
  let(:file) { '/RAILS_ROOT/config/class.yml' }
19
19
 
20
20
  it 'loads default file' do
21
- expect_any_instance_of(Configuration).to receive(:raw_file).with(file)
22
- HasConfiguration::Configuration.new(klass)
21
+ configuration = described_class.new(klass)
22
+ expect(configuration).to have_received(:raw_file).with(file)
23
23
  end
24
24
  end
25
25
 
@@ -27,8 +27,8 @@ RSpec.describe HasConfiguration::Configuration do
27
27
  let(:file) { 'foo/bar.yml' }
28
28
 
29
29
  it 'loads provided file' do
30
- expect_any_instance_of(Configuration).to receive(:raw_file).with(file)
31
- HasConfiguration::Configuration.new(klass, file: file)
30
+ configuration = described_class.new(klass, file: file)
31
+ expect(configuration).to have_received(:raw_file).with(file)
32
32
  end
33
33
  end
34
34
  end
@@ -36,32 +36,31 @@ RSpec.describe HasConfiguration::Configuration do
36
36
  context 'when initialized' do
37
37
  let(:environment) { nil }
38
38
 
39
- context 'environment' do
40
- let(:fixture) { 'spec/fixtures/class.yml' }
39
+ context 'without env option' do
40
+ subject(:hash) { described_class.new(klass).to_h }
41
41
 
42
- context 'without env option' do
43
- subject(:hash) { HasConfiguration::Configuration.new(klass).to_h }
42
+ let(:fixture) { 'spec/fixtures/class.yml' }
44
43
 
45
- it 'return the expected hash' do
46
- expect(hash).to eq('env' => 'test')
47
- end
44
+ it 'return the expected hash' do
45
+ expect(hash).to eq('env' => 'test')
48
46
  end
47
+ end
49
48
 
50
- context 'with env option' do
51
- let(:environment) { 'production' }
49
+ context 'with env option' do
50
+ subject(:hash) { described_class.new(klass, env: environment).to_h }
52
51
 
53
- subject(:hash) { HasConfiguration::Configuration.new(klass, env: environment).to_h }
52
+ let(:environment) { 'production' }
53
+ let(:fixture) { 'spec/fixtures/class.yml' }
54
54
 
55
- it 'return the expected hash' do
56
- expect(hash).to eq('env' => environment)
57
- end
55
+ it 'return the expected hash' do
56
+ expect(hash).to eq('env' => environment)
58
57
  end
59
58
  end
60
59
 
61
- context 'yaml defaults' do
62
- let(:fixture) { 'spec/fixtures/with_defaults.yml' }
60
+ context 'with yaml defaults' do
61
+ subject(:hash) { described_class.new(klass).to_h }
63
62
 
64
- subject(:hash) { HasConfiguration::Configuration.new(klass).to_h }
63
+ let(:fixture) { 'spec/fixtures/with_defaults.yml' }
65
64
 
66
65
  it 'return the expected hash' do
67
66
  expect(hash).to eq('default' => 'default', 'env' => 'test')
@@ -69,9 +68,9 @@ RSpec.describe HasConfiguration::Configuration do
69
68
  end
70
69
 
71
70
  context 'with erb' do
72
- let(:fixture) { 'spec/fixtures/with_erb.yml' }
71
+ subject(:hash) { described_class.new(klass).to_h }
73
72
 
74
- subject(:hash) { HasConfiguration::Configuration.new(klass).to_h }
73
+ let(:fixture) { 'spec/fixtures/with_erb.yml' }
75
74
 
76
75
  it 'return the expected hash' do
77
76
  expect(hash).to eq('erb' => Rails.env)
@@ -82,27 +81,30 @@ RSpec.describe HasConfiguration::Configuration do
82
81
  describe '#to_h' do
83
82
  let(:fixture) { 'spec/fixtures/with_nested_attributes.yml' }
84
83
 
85
- context '#to_h' do
86
- subject { HasConfiguration::Configuration.new(klass).to_h }
87
- it { should be_a(HashWithIndifferentAccess) }
84
+ context 'without arguments' do
85
+ subject { described_class.new(klass).to_h }
86
+
87
+ it { is_expected.to be_a(HashWithIndifferentAccess) }
88
88
  end
89
89
 
90
- context '#to_h(:stringify)' do
91
- subject { HasConfiguration::Configuration.new(klass).to_h(:stringify) }
92
- it { should eq('env' => 'test', 'nested' => { 'foo' => 'bar', 'baz' => true }) }
90
+ context 'with :stringify' do
91
+ subject { described_class.new(klass).to_h(:stringify) }
92
+
93
+ it { is_expected.to eq('env' => 'test', 'nested' => { 'foo' => 'bar', 'baz' => true }) }
93
94
  end
94
95
 
95
- context '#to_h(:symbolized)' do
96
- subject { HasConfiguration::Configuration.new(klass).to_h(:symbolized) }
97
- it { should eq(env: 'test', nested: { foo: 'bar', baz: true }) }
96
+ context 'with :symbolized' do
97
+ subject { described_class.new(klass).to_h(:symbolized) }
98
+
99
+ it { is_expected.to eq(env: 'test', nested: { foo: 'bar', baz: true }) }
98
100
  end
99
101
  end
100
102
 
101
103
  describe 'struct methods' do
102
- let(:configuration) { HasConfiguration::Configuration.new(klass) }
104
+ let(:configuration) { described_class.new(klass) }
103
105
  let(:fixture) { 'spec/fixtures/with_nested_attributes.yml' }
104
106
 
105
- it 'is structified' do
107
+ it 'supports multiple getter variants' do # rubocop:disable RSpec/MultipleExpectations
106
108
  expect(configuration.to_h[:env]).to eql('test')
107
109
  expect(configuration.env).to eql('test')
108
110
 
@@ -1,29 +1,27 @@
1
1
  RSpec.describe HasConfiguration do
2
2
  context 'when declared' do
3
- before(:all) do
4
- Dummy = Class.new do
5
- require 'has_configuration'
6
- has_configuration file: 'spec/fixtures/class.yml'
7
- end
3
+ Dummy = Class.new do
4
+ require 'has_configuration'
5
+ has_configuration file: 'spec/fixtures/class.yml'
8
6
  end
9
7
 
10
- context 'the class' do
8
+ context 'with a class' do
11
9
  subject(:dummy) { Dummy }
12
10
 
13
- it { should respond_to(:configuration) }
11
+ it { is_expected.to respond_to(:configuration) }
14
12
 
15
13
  it 'returns a configuration' do
16
- expect(dummy.configuration).to be
14
+ expect(dummy.configuration).to be_present
17
15
  end
18
16
  end
19
17
 
20
- context 'an instance' do
18
+ context 'with an instance' do
21
19
  subject(:dummy) { Dummy.new }
22
20
 
23
- it { should respond_to(:configuration) }
21
+ it { is_expected.to respond_to(:configuration) }
24
22
 
25
23
  it 'returns a configuration' do
26
- expect(dummy.configuration).to be
24
+ expect(dummy.configuration).to be_present
27
25
  end
28
26
  end
29
27
  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: 3.0.0
4
+ version: 3.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Spickermann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-26 00:00:00.000000000 Z
11
+ date: 2019-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop-rspec
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'
83
97
  description: |2
84
98
  Loads configuration setting from a yml file and adds a configuation method
85
99
  to class and instances
@@ -120,8 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
134
  - !ruby/object:Gem::Version
121
135
  version: '0'
122
136
  requirements: []
123
- rubyforge_project:
124
- rubygems_version: 2.7.3
137
+ rubygems_version: 3.0.1
125
138
  signing_key:
126
139
  specification_version: 4
127
140
  summary: Simple configuration handling