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 +4 -4
- data/lib/has_configuration/configuration.rb +11 -7
- data/lib/has_configuration.rb +1 -1
- data/lib/version.rb +1 -1
- data/spec/lib/has_configuration/configuration_spec.rb +36 -34
- data/spec/lib/has_configuration_spec.rb +9 -11
- metadata +17 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 434cfdd0e94cbe7c1a355fbe98c4ba7ed644a531f788312005274a5dd4329fd8
|
4
|
+
data.tar.gz: d5fc4f5af682a4269a891b78d288a4c8215e5955d9e054868cf52ca2176a82db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 =
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
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.
|
72
|
+
return @options[:env] if @options.key?(:env)
|
69
73
|
return Rails.env.to_s if defined?(Rails)
|
70
74
|
end
|
71
75
|
|
data/lib/has_configuration.rb
CHANGED
data/lib/version.rb
CHANGED
@@ -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
|
-
|
22
|
-
|
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
|
-
|
31
|
-
|
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 '
|
40
|
-
|
39
|
+
context 'without env option' do
|
40
|
+
subject(:hash) { described_class.new(klass).to_h }
|
41
41
|
|
42
|
-
|
43
|
-
subject(:hash) { HasConfiguration::Configuration.new(klass).to_h }
|
42
|
+
let(:fixture) { 'spec/fixtures/class.yml' }
|
44
43
|
|
45
|
-
|
46
|
-
|
47
|
-
end
|
44
|
+
it 'return the expected hash' do
|
45
|
+
expect(hash).to eq('env' => 'test')
|
48
46
|
end
|
47
|
+
end
|
49
48
|
|
50
|
-
|
51
|
-
|
49
|
+
context 'with env option' do
|
50
|
+
subject(:hash) { described_class.new(klass, env: environment).to_h }
|
52
51
|
|
53
|
-
|
52
|
+
let(:environment) { 'production' }
|
53
|
+
let(:fixture) { 'spec/fixtures/class.yml' }
|
54
54
|
|
55
|
-
|
56
|
-
|
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
|
-
|
60
|
+
context 'with yaml defaults' do
|
61
|
+
subject(:hash) { described_class.new(klass).to_h }
|
63
62
|
|
64
|
-
|
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
|
-
|
71
|
+
subject(:hash) { described_class.new(klass).to_h }
|
73
72
|
|
74
|
-
|
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 '
|
86
|
-
subject {
|
87
|
-
|
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 '
|
91
|
-
subject {
|
92
|
-
|
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 '
|
96
|
-
subject {
|
97
|
-
|
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) {
|
104
|
+
let(:configuration) { described_class.new(klass) }
|
103
105
|
let(:fixture) { 'spec/fixtures/with_nested_attributes.yml' }
|
104
106
|
|
105
|
-
it '
|
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
|
-
|
4
|
-
|
5
|
-
|
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 '
|
8
|
+
context 'with a class' do
|
11
9
|
subject(:dummy) { Dummy }
|
12
10
|
|
13
|
-
it {
|
11
|
+
it { is_expected.to respond_to(:configuration) }
|
14
12
|
|
15
13
|
it 'returns a configuration' do
|
16
|
-
expect(dummy.configuration).to
|
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 {
|
21
|
+
it { is_expected.to respond_to(:configuration) }
|
24
22
|
|
25
23
|
it 'returns a configuration' do
|
26
|
-
expect(dummy.configuration).to
|
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.
|
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:
|
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
|
-
|
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
|