a9n 0.6.2 → 0.7.0

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.
@@ -12,15 +12,17 @@ module A9n
12
12
  data
13
13
  end
14
14
 
15
+ alias to_h to_hash
16
+
15
17
  def merge(another_data)
16
18
  data.merge!(another_data)
17
19
  end
18
20
 
19
- def method_missing(name, *args)
21
+ def method_missing(name, *_args)
20
22
  if data.key?(name)
21
23
  fetch(name)
22
24
  else
23
- fail NoSuchConfigurationVariableError.new(name)
25
+ raise NoSuchConfigurationVariableError.new, name
24
26
  end
25
27
  end
26
28
 
@@ -1,3 +1,3 @@
1
1
  module A9n
2
- VERSION = "0.6.2"
2
+ VERSION = '0.7.0'.freeze
3
3
  end
@@ -1,38 +1,38 @@
1
1
  RSpec.describe A9n do
2
2
  subject { described_class }
3
3
 
4
- let(:env) { "test" }
4
+ let(:env) { 'test' }
5
5
 
6
6
  before do
7
7
  clean_singleton(subject)
8
- ENV["ERB_DWARF"] = "erbized dwarf"
9
- ENV["DWARF_PASSWORD"] = "dwarf123"
10
- ENV["MANDRILL_API_KEY"] = "ASDF1234"
11
- ENV["API_KEY"] = "XYZ999"
8
+ ENV['ERB_DWARF'] = 'erbized dwarf'
9
+ ENV['DWARF_PASSWORD'] = 'dwarf123'
10
+ ENV['MANDRILL_API_KEY'] = 'ASDF1234'
11
+ ENV['API_KEY'] = 'XYZ999'
12
12
  subject.app = double(env: env)
13
- subject.root = File.expand_path("../../../test_app", __FILE__)
13
+ subject.root = File.expand_path('../../test_app', __dir__)
14
14
  subject.load
15
15
  end
16
16
 
17
17
  after do
18
18
  clean_singleton(subject)
19
- ENV.delete("MANDRILL_API_KEY")
20
- ENV.delete("API_KEY")
19
+ ENV.delete('MANDRILL_API_KEY')
20
+ ENV.delete('API_KEY')
21
21
  end
22
22
 
23
- context "base config file" do
23
+ context 'base config file' do
24
24
  it do
25
25
  expect(subject.storage).to be_kind_of(A9n::Struct)
26
26
  end
27
27
 
28
28
  it do
29
- expect(subject.default_dwarf).to eq("default dwarf")
30
- expect(subject.overriden_dwarf).to eq("already overriden dwarf")
29
+ expect(subject.default_dwarf).to eq('default dwarf')
30
+ expect(subject.overriden_dwarf).to eq('already overriden dwarf')
31
31
  end
32
32
 
33
33
  it do
34
- expect(subject.fetch(:default_dwarf)).to eq("default dwarf")
35
- expect(subject.fetch(:overriden_dwarf)).to eq("already overriden dwarf")
34
+ expect(subject.fetch(:default_dwarf)).to eq('default dwarf')
35
+ expect(subject.fetch(:overriden_dwarf)).to eq('already overriden dwarf')
36
36
  end
37
37
 
38
38
  it do
@@ -44,37 +44,37 @@ RSpec.describe A9n do
44
44
  end
45
45
 
46
46
  it do
47
- expect { subject.fetch(:invalid, "Hello").to eq("Hello") }
47
+ expect { subject.fetch(:invalid, 'Hello').to eq('Hello') }
48
48
  end
49
49
  end
50
50
 
51
- context "undefined env" do
52
- let(:env) { "tropical" }
51
+ context 'undefined env' do
52
+ let(:env) { 'tropical' }
53
53
 
54
54
  it do
55
- expect(subject.default_dwarf).to eq("default dwarf")
56
- expect(subject.overriden_dwarf).to eq("not yet overriden dwarf")
55
+ expect(subject.default_dwarf).to eq('default dwarf')
56
+ expect(subject.overriden_dwarf).to eq('not yet overriden dwarf')
57
57
  end
58
58
 
59
59
  it do
60
- expect(subject.fetch(:default_dwarf)).to eq("default dwarf")
61
- expect(subject.fetch(:overriden_dwarf)).to eq("not yet overriden dwarf")
60
+ expect(subject.fetch(:default_dwarf)).to eq('default dwarf')
61
+ expect(subject.fetch(:overriden_dwarf)).to eq('not yet overriden dwarf')
62
62
  end
63
63
  end
64
64
 
65
- context "extra config file" do
65
+ context 'extra config file' do
66
66
  before do
67
67
  expect(subject.mandrill).to be_kind_of(A9n::Struct)
68
68
  end
69
69
 
70
70
  it do
71
- expect(subject.mandrill.username).to eq("joe")
72
- expect(subject.mandrill.api_key).to eq("ASDF1234")
71
+ expect(subject.mandrill.username).to eq('joe')
72
+ expect(subject.mandrill.api_key).to eq('ASDF1234')
73
73
  end
74
74
 
75
75
  it do
76
- expect(subject.mandrill.fetch(:username)).to eq("joe")
77
- expect(subject.mandrill.fetch(:api_key)).to eq("ASDF1234")
76
+ expect(subject.mandrill.fetch(:username)).to eq('joe')
77
+ expect(subject.mandrill.fetch(:api_key)).to eq('ASDF1234')
78
78
  end
79
79
 
80
80
  it do
@@ -82,19 +82,19 @@ RSpec.describe A9n do
82
82
  end
83
83
  end
84
84
 
85
- context "extra config file with erb" do
85
+ context 'extra config file with erb' do
86
86
  before do
87
87
  expect(subject.cloud).to be_kind_of(A9n::Struct)
88
88
  end
89
89
 
90
90
  it do
91
- expect(subject.cloud.username).to eq("testuser")
92
- expect(subject.cloud.password).to eq("qwerty")
91
+ expect(subject.cloud.username).to eq('testuser')
92
+ expect(subject.cloud.password).to eq('qwerty')
93
93
  end
94
94
 
95
95
  it do
96
- expect(subject.cloud.fetch(:username)).to eq("testuser")
97
- expect(subject.cloud.fetch(:password)).to eq("qwerty")
96
+ expect(subject.cloud.fetch(:username)).to eq('testuser')
97
+ expect(subject.cloud.fetch(:password)).to eq('qwerty')
98
98
  end
99
99
 
100
100
  it do
@@ -102,17 +102,17 @@ RSpec.describe A9n do
102
102
  end
103
103
  end
104
104
 
105
- context "extra config file with example" do
105
+ context 'extra config file with example' do
106
106
  before do
107
107
  expect(subject.mailer).to be_kind_of(A9n::Struct)
108
108
  end
109
109
 
110
110
  it do
111
- expect(subject.mailer.delivery_method).to eq("test")
111
+ expect(subject.mailer.delivery_method).to eq('test')
112
112
  end
113
113
 
114
114
  it do
115
- expect(subject.mailer.fetch(:delivery_method)).to eq("test")
115
+ expect(subject.mailer.fetch(:delivery_method)).to eq('test')
116
116
  end
117
117
 
118
118
  it do
@@ -1,11 +1,11 @@
1
- require "simplecov"
1
+ require 'simplecov'
2
2
  SimpleCov.start
3
3
 
4
- require "rubygems"
5
- require "bundler/setup"
4
+ require 'rubygems'
5
+ require 'bundler/setup'
6
6
 
7
- require "a9n"
8
- require "pry"
7
+ require 'a9n'
8
+ require 'pry'
9
9
 
10
10
  RSpec.configure do |config|
11
11
  # rspec-expectations config goes here. You can use an alternate
@@ -16,9 +16,9 @@ RSpec.configure do |config|
16
16
  # and `failure_message` of custom matchers include text for helper methods
17
17
  # defined using `chain`, e.g.:
18
18
  # be_bigger_than(2).and_smaller_than(4).description
19
- # # => "be bigger than 2 and smaller than 4"
19
+ # # => 'be bigger than 2 and smaller than 4'
20
20
  # ...rather than:
21
- # # => "be bigger than 2"
21
+ # # => 'be bigger than 2'
22
22
  expectations.include_chain_clauses_in_custom_matcher_descriptions = true
23
23
  end
24
24
 
@@ -48,7 +48,7 @@ RSpec.configure do |config|
48
48
  # Allows RSpec to persist some state between runs in order to support
49
49
  # the `--only-failures` and `--next-failure` CLI options. We recommend
50
50
  # you configure your source control system to ignore this file.
51
- config.example_status_persistence_file_path = "spec/examples.txt"
51
+ config.example_status_persistence_file_path = 'spec/examples.txt'
52
52
 
53
53
  # Limits the available syntax to the non-monkey patched syntax that is
54
54
  # recommended. For more details, see:
@@ -91,9 +91,6 @@ end
91
91
 
92
92
  def clean_singleton(klass)
93
93
  [:@storage, :@env, :@app, :@root].each do |var|
94
- if klass.instance_variable_defined?(var)
95
- klass.remove_instance_variable(var)
96
- end
94
+ klass.instance_variable_defined?(var) && klass.remove_instance_variable(var)
97
95
  end
98
96
  end
99
-
@@ -3,42 +3,42 @@ RSpec.describe A9n do
3
3
  before { clean_singleton(subject) }
4
4
  after { clean_singleton(subject) }
5
5
 
6
- describe ".env" do
6
+ describe '.env' do
7
7
  before do
8
8
  subject.instance_variable_set(:@env, nil)
9
9
  end
10
10
 
11
- context "app_env is set" do
11
+ context 'app_env is set' do
12
12
  before do
13
- expect(subject).to receive(:app).and_return(double(env: ::A9n::StringInquirer.new("dwarf_env"))).exactly(3).times
13
+ expect(subject).to receive(:app).and_return(double(env: ::A9n::StringInquirer.new('dwarf_env')))
14
14
  expect(subject).to receive(:env_var).never
15
15
  end
16
16
 
17
17
  it do
18
- expect(subject.env).to eq("dwarf_env")
18
+ expect(subject.env).to eq('dwarf_env')
19
19
  expect(subject.env.dwarf_env?).to eq(true)
20
20
  expect(subject.env.production?).to eq(false)
21
21
  end
22
22
  end
23
23
 
24
- context "when APP_ENV is set" do
24
+ context 'when APP_ENV is set' do
25
25
  before do
26
26
  expect(subject).to receive(:app_env).and_return(nil)
27
- expect(subject).to receive(:env_var).with("RAILS_ENV").and_return(nil)
28
- expect(subject).to receive(:env_var).with("RACK_ENV").and_return(nil)
29
- expect(subject).to receive(:env_var).with("APP_ENV").and_return("dwarf_env")
27
+ expect(subject).to receive(:env_var).with('RAILS_ENV').and_return(nil)
28
+ expect(subject).to receive(:env_var).with('RACK_ENV').and_return(nil)
29
+ expect(subject).to receive(:env_var).with('APP_ENV').and_return('dwarf_env')
30
30
  end
31
31
 
32
32
  it do
33
- expect(subject.env).to eq("dwarf_env")
33
+ expect(subject.env).to eq('dwarf_env')
34
34
  expect(subject.env.dwarf_env?).to eq(true)
35
35
  expect(subject.env.production?).to eq(false)
36
36
  end
37
37
  end
38
38
  end
39
39
 
40
- describe ".app" do
41
- context "when rails not found" do
40
+ describe '.app' do
41
+ context 'when rails not found' do
42
42
  before do
43
43
  expect(subject).to receive(:rails_app).and_return(nil)
44
44
  end
@@ -48,8 +48,8 @@ RSpec.describe A9n do
48
48
  end
49
49
  end
50
50
 
51
- context "when rails app is being used" do
52
- let(:app) { double(env: "test", root: "/apps/a9n") }
51
+ context 'when rails app is being used' do
52
+ let(:app) { double(env: 'test', root: '/apps/a9n') }
53
53
 
54
54
  before do
55
55
  expect(subject).to receive(:rails_app).and_return(app)
@@ -60,8 +60,8 @@ RSpec.describe A9n do
60
60
  end
61
61
  end
62
62
 
63
- context "when custom non-rails app is being used" do
64
- let(:app) { double(env: "test", root: "/apps/a9n") }
63
+ context 'when custom non-rails app is being used' do
64
+ let(:app) { double(env: 'test', root: '/apps/a9n') }
65
65
 
66
66
  before do
67
67
  subject.app = app
@@ -73,60 +73,60 @@ RSpec.describe A9n do
73
73
  end
74
74
  end
75
75
 
76
- describe ".root" do
77
- context "when app is set" do
78
- let(:app) { double(env: "test", root: "/apps/a9n") }
76
+ describe '.root' do
77
+ context 'when app is set' do
78
+ let(:app) { double(env: 'test', root: '/apps/a9n') }
79
79
 
80
80
  before do
81
81
  subject.app = app
82
82
  end
83
83
 
84
- context "with custom path" do
84
+ context 'with custom path' do
85
85
  before do
86
- subject.root = "/home/knapo/workspace/a9n"
86
+ subject.root = '/home/knapo/workspace/a9n'
87
87
  end
88
88
 
89
89
  it do
90
- expect(subject.root).to eq(Pathname.new("/home/knapo/workspace/a9n"))
90
+ expect(subject.root).to eq(Pathname.new('/home/knapo/workspace/a9n'))
91
91
  end
92
92
  end
93
93
 
94
- context "with local app path" do
94
+ context 'with local app path' do
95
95
  it do
96
- expect(subject.root).to eq("/apps/a9n")
96
+ expect(subject.root).to eq('/apps/a9n')
97
97
  end
98
98
  end
99
99
  end
100
100
 
101
- context "when app is not set" do
101
+ context 'when app is not set' do
102
102
  it do
103
103
  expect(subject.root).to eq(nil)
104
104
  end
105
105
 
106
- context "when setting a custom path when is falsy" do
106
+ context 'when setting a custom path when is falsy' do
107
107
  before do
108
- subject.root ||= "/home/knapo/workspace/a9n"
108
+ subject.root ||= '/home/knapo/workspace/a9n'
109
109
  end
110
110
 
111
111
  it do
112
- expect(subject.root).to eq(Pathname.new("/home/knapo/workspace/a9n"))
112
+ expect(subject.root).to eq(Pathname.new('/home/knapo/workspace/a9n'))
113
113
  end
114
114
  end
115
115
 
116
- context "when setting a custom path" do
116
+ context 'when setting a custom path' do
117
117
  before do
118
- subject.root = "/home/knapo/workspace/a9n"
118
+ subject.root = '/home/knapo/workspace/a9n'
119
119
  end
120
120
 
121
121
  it do
122
- expect(subject.root).to eq(Pathname.new("/home/knapo/workspace/a9n"))
122
+ expect(subject.root).to eq(Pathname.new('/home/knapo/workspace/a9n'))
123
123
  end
124
124
  end
125
125
  end
126
126
  end
127
127
 
128
- describe ".rails_app" do
129
- context "when defined" do
128
+ describe '.rails_app' do
129
+ context 'when defined' do
130
130
  before do
131
131
  Object.const_set(:Rails, Module.new)
132
132
  end
@@ -140,54 +140,54 @@ RSpec.describe A9n do
140
140
  end
141
141
  end
142
142
 
143
- context "when not defined" do
143
+ context 'when not defined' do
144
144
  it do
145
145
  expect(subject.rails_app).to be_nil
146
146
  end
147
147
  end
148
148
  end
149
149
 
150
- describe ".env_var" do
150
+ describe '.env_var' do
151
151
  before do
152
- ENV["DWARF"] = "little dwarf"
152
+ ENV['DWARF'] = 'little dwarf'
153
153
  end
154
154
 
155
155
  it do
156
- expect(subject.env_var("DWARF")).to eq("little dwarf")
156
+ expect(subject.env_var('DWARF')).to eq('little dwarf')
157
157
  end
158
158
 
159
159
  it do
160
- expect(subject.env_var("IS_DWARF")).to be_nil
160
+ expect(subject.env_var('IS_DWARF')).to be_nil
161
161
  end
162
162
  end
163
163
 
164
- describe ".default_files" do
164
+ describe '.default_files' do
165
165
  before do
166
- subject.root = File.expand_path("../../../test_app", __FILE__)
166
+ subject.root = File.expand_path('../../test_app', __dir__)
167
167
  end
168
168
 
169
169
  it do
170
- expect(subject.default_files[0]).to include("configuration.yml")
170
+ expect(subject.default_files[0]).to include('configuration.yml')
171
171
  expect(Pathname.new(subject.default_files[0])).to be_absolute
172
- expect(subject.default_files[1]).to include("a9n/mandrill.yml")
172
+ expect(subject.default_files[1]).to include('a9n/mandrill.yml')
173
173
  expect(Pathname.new(subject.default_files[1])).to be_absolute
174
174
  end
175
175
  end
176
176
 
177
- describe ".load" do
177
+ describe '.load' do
178
178
  before do
179
- expect(described_class).to receive(:env).exactly(2).times.and_return("dev")
180
- subject.root = "/apps/test_app"
179
+ expect(described_class).to receive(:env).exactly(2).times.and_return('dev')
180
+ subject.root = '/apps/test_app'
181
181
  files.each do |f, cfg|
182
- expect(A9n::Loader).to receive(:new).with(f, kind_of(A9n::Scope), "dev").and_return(double(get: cfg))
182
+ expect(A9n::Loader).to receive(:new).with(f, kind_of(A9n::Scope), 'dev').and_return(double(get: cfg))
183
183
  end
184
184
  end
185
185
 
186
- context "when no files given" do
186
+ context 'when no files given' do
187
187
  let(:files) do
188
188
  {
189
- "/apps/test_app/config/file1.yml" => { host: "host1.com" },
190
- "/apps/test_app/config/dir/file2.yml" => { host: "host2.com" }
189
+ '/apps/test_app/config/file1.yml' => { host: 'host1.com' },
190
+ '/apps/test_app/config/dir/file2.yml' => { host: 'host2.com' }
191
191
  }
192
192
  end
193
193
 
@@ -201,15 +201,15 @@ RSpec.describe A9n do
201
201
  end
202
202
  end
203
203
 
204
- context "when custom files given" do
204
+ context 'when custom files given' do
205
205
  let(:given_files) do
206
- ["file3.yml", "/apps/test_app/config/dir/file4.yml"]
206
+ ['file3.yml', '/apps/test_app/config/dir/file4.yml']
207
207
  end
208
208
 
209
209
  let(:files) do
210
210
  {
211
- "/apps/test_app/config/file3.yml" => { host: "host3.com" },
212
- "/apps/test_app/config/dir/file4.yml" => { host: "host4.com" }
211
+ '/apps/test_app/config/file3.yml' => { host: 'host3.com' },
212
+ '/apps/test_app/config/dir/file4.yml' => { host: 'host4.com' }
213
213
  }
214
214
  end
215
215
 
@@ -224,8 +224,8 @@ RSpec.describe A9n do
224
224
  end
225
225
  end
226
226
 
227
- describe ".method_missing" do
228
- context "when storage is empty" do
227
+ describe '.method_missing' do
228
+ context 'when storage is empty' do
229
229
  before do
230
230
  expect(subject).to receive(:load).once
231
231
  end
@@ -236,7 +236,7 @@ RSpec.describe A9n do
236
236
  end
237
237
  end
238
238
 
239
- context "when storage is not empty" do
239
+ context 'when storage is not empty' do
240
240
  before do
241
241
  subject.storage[:whenever] = 'whenever'
242
242
  expect(subject).not_to receive(:load)