a9n 0.1.1 → 0.1.2
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/.travis.yml +1 -5
- data/Gemfile +2 -2
- data/README.md +1 -1
- data/Rakefile +1 -1
- data/lib/a9n.rb +9 -5
- data/lib/a9n/struct.rb +1 -5
- data/lib/a9n/version.rb +1 -1
- data/spec/a9n_spec.rb +67 -19
- data/spec/spec_helper.rb +11 -3
- data/spec/struct_spec.rb +2 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14a5336e3c89478cdefd0df4a7c71dd78e809b10
|
4
|
+
data.tar.gz: 5ddb8cbb02e172e3bd26e43c2397ae0d49581a9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84e86886b37e5c7f785f6c9e9b0221aa05c9b0feced8f7992328d9bc475ff4842272d6011ef98cedb7153b289a40f63390e278d8a17ebde5647e71eccf3614b2
|
7
|
+
data.tar.gz: 4995758ee232692f671f8f944865712ff169bdb4ac0c166a0fe6ce0eebd95295f35909a6d35189dca44b5913c139565f58531309c8cf7ca37633a61f3c98a097
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
[codeclimate]: https://codeclimate.com/github/knapo/a9n
|
11
11
|
[coveralls]: https://coveralls.io/r/knapo/a9n
|
12
12
|
|
13
|
-
Simple tool for managing ruby/rails
|
13
|
+
Simple tool for managing extra configuration in ruby/rails apps. Supports Rails 2.x, 3.x, 4.x and Ruby 1.9, 2.0. For Ruby 1.8 use version < 1.0
|
14
14
|
|
15
15
|
## Installation
|
16
16
|
|
data/Rakefile
CHANGED
data/lib/a9n.rb
CHANGED
@@ -18,7 +18,7 @@ module A9n
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def env
|
21
|
-
@env ||= local_app_env ||
|
21
|
+
@env ||= local_app_env || get_env_var('RAILS_ENV') || get_env_var('RACK_ENV') || get_env_var('APP_ENV')
|
22
22
|
end
|
23
23
|
|
24
24
|
def local_app_env
|
@@ -82,6 +82,14 @@ module A9n
|
|
82
82
|
config.send(name, *args)
|
83
83
|
end
|
84
84
|
|
85
|
+
def get_rails
|
86
|
+
defined?(Rails) ? Rails : nil
|
87
|
+
end
|
88
|
+
|
89
|
+
def get_env_var(name)
|
90
|
+
ENV[name]
|
91
|
+
end
|
92
|
+
|
85
93
|
private
|
86
94
|
|
87
95
|
def verify!(base, local)
|
@@ -90,9 +98,5 @@ module A9n
|
|
90
98
|
raise MissingConfigurationVariables.new("Following variables are missing in your configuration file: #{missing_keys.join(',')}")
|
91
99
|
end
|
92
100
|
end
|
93
|
-
|
94
|
-
def get_rails
|
95
|
-
defined?(Rails) ? Rails : nil
|
96
|
-
end
|
97
101
|
end
|
98
102
|
end
|
data/lib/a9n/struct.rb
CHANGED
data/lib/a9n/version.rb
CHANGED
data/spec/a9n_spec.rb
CHANGED
@@ -4,7 +4,7 @@ describe A9n do
|
|
4
4
|
describe '.local_app' do
|
5
5
|
context 'when rails not found' do
|
6
6
|
before {
|
7
|
-
described_class.
|
7
|
+
expect(described_class).to receive(:get_rails).and_return(nil)
|
8
8
|
}
|
9
9
|
specify {
|
10
10
|
described_class.local_app.should be_nil
|
@@ -12,7 +12,7 @@ describe A9n do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
context 'when custom non-rails app is being used' do
|
15
|
-
let(:local_app) {
|
15
|
+
let(:local_app) { double(:env => 'test', :root => '/apps/a9n') }
|
16
16
|
before { described_class.local_app = local_app }
|
17
17
|
|
18
18
|
specify { described_class.local_app.should == local_app }
|
@@ -22,7 +22,7 @@ describe A9n do
|
|
22
22
|
end
|
23
23
|
|
24
24
|
describe '.root' do
|
25
|
-
let(:local_app) {
|
25
|
+
let(:local_app) { double(:env => 'test', :root => '/apps/a9n') }
|
26
26
|
before { described_class.local_app = local_app }
|
27
27
|
|
28
28
|
context 'with custom path' do
|
@@ -57,9 +57,9 @@ describe A9n do
|
|
57
57
|
|
58
58
|
context 'when no configuration file exists' do
|
59
59
|
before do
|
60
|
-
described_class.
|
61
|
-
described_class.
|
62
|
-
described_class.
|
60
|
+
expect(described_class).to receive(:load_yml).with('config/configuration.yml.example').and_return(nil)
|
61
|
+
expect(described_class).to receive(:load_yml).with('config/configuration.yml').and_return(nil)
|
62
|
+
expect(described_class).to receive(:verify!).never
|
63
63
|
end
|
64
64
|
it 'raises expection' do
|
65
65
|
lambda {
|
@@ -70,13 +70,14 @@ describe A9n do
|
|
70
70
|
|
71
71
|
context 'when base configuration file exists' do
|
72
72
|
before do
|
73
|
-
described_class.
|
74
|
-
described_class.
|
75
|
-
described_class.
|
73
|
+
expect(described_class).to receive(:load_yml).with('config/configuration.yml.example').and_return(base_sample_config)
|
74
|
+
expect(described_class).to receive(:load_yml).with('config/configuration.yml').and_return(nil)
|
75
|
+
expect(described_class).to receive(:verify!).never
|
76
76
|
described_class.load
|
77
77
|
end
|
78
78
|
|
79
79
|
its(:app_url) { should_not be_nil }
|
80
|
+
its(:app_url) { should == subject.fetch(:app_url) }
|
80
81
|
specify {
|
81
82
|
expect { subject.app_host }.to raise_error(described_class::NoSuchConfigurationVariable)
|
82
83
|
}
|
@@ -84,9 +85,9 @@ describe A9n do
|
|
84
85
|
|
85
86
|
context 'when local configuration file exists' do
|
86
87
|
before do
|
87
|
-
described_class.
|
88
|
-
described_class.
|
89
|
-
described_class.
|
88
|
+
expect(described_class).to receive(:load_yml).with('config/configuration.yml.example').and_return(nil)
|
89
|
+
expect(described_class).to receive(:load_yml).with('config/configuration.yml').and_return(local_sample_config)
|
90
|
+
expect(described_class).to receive(:verify!).never
|
90
91
|
described_class.load
|
91
92
|
end
|
92
93
|
|
@@ -99,8 +100,8 @@ describe A9n do
|
|
99
100
|
context 'when both local and base configuration file exists' do
|
100
101
|
context 'with same data' do
|
101
102
|
before do
|
102
|
-
described_class.
|
103
|
-
described_class.
|
103
|
+
expect(described_class).to receive(:load_yml).with('config/configuration.yml.example').and_return(base_sample_config)
|
104
|
+
expect(described_class).to receive(:load_yml).with('config/configuration.yml').and_return(base_sample_config)
|
104
105
|
described_class.load
|
105
106
|
end
|
106
107
|
|
@@ -112,8 +113,8 @@ describe A9n do
|
|
112
113
|
|
113
114
|
context 'with different data' do
|
114
115
|
before do
|
115
|
-
described_class.
|
116
|
-
described_class.
|
116
|
+
expect(described_class).to receive(:load_yml).with('config/configuration.yml.example').and_return(base_sample_config)
|
117
|
+
expect(described_class).to receive(:load_yml).with('config/configuration.yml').and_return(local_sample_config)
|
117
118
|
end
|
118
119
|
it 'raises expection' do
|
119
120
|
expect {
|
@@ -129,11 +130,11 @@ describe A9n do
|
|
129
130
|
subject { described_class.load_yml(file_path) }
|
130
131
|
|
131
132
|
before do
|
132
|
-
described_class.
|
133
|
+
expect(described_class).to receive(:root).at_least(:once).and_return(root)
|
133
134
|
end
|
134
135
|
|
135
136
|
context 'when file not exists' do
|
136
|
-
before { described_class.
|
137
|
+
before { expect(described_class).to receive(:env).never }
|
137
138
|
let(:file_path) { 'file_not_existing_in_universe.yml' }
|
138
139
|
|
139
140
|
it 'returns nil' do
|
@@ -145,7 +146,7 @@ describe A9n do
|
|
145
146
|
let(:file_path) { 'fixtures/configuration.yml'}
|
146
147
|
before {
|
147
148
|
ENV['DWARF'] = 'erbized dwarf'
|
148
|
-
described_class.
|
149
|
+
expect(described_class).to receive(:env).twice.and_return(env)
|
149
150
|
}
|
150
151
|
|
151
152
|
context 'and has data' do
|
@@ -178,4 +179,51 @@ describe A9n do
|
|
178
179
|
end
|
179
180
|
end
|
180
181
|
end
|
182
|
+
|
183
|
+
describe '.env' do
|
184
|
+
before {
|
185
|
+
described_class.instance_variable_set(:@env, nil)
|
186
|
+
}
|
187
|
+
|
188
|
+
context 'local_app_env is set' do
|
189
|
+
before {
|
190
|
+
expect(described_class).to receive(:local_app).and_return(double(:env => 'dwarf_env')).exactly(3).times
|
191
|
+
expect(described_class).to receive(:get_env_var).never
|
192
|
+
}
|
193
|
+
its(:env) { should == 'dwarf_env' }
|
194
|
+
end
|
195
|
+
|
196
|
+
context "when APP_ENV is set" do
|
197
|
+
before {
|
198
|
+
expect(described_class).to receive(:local_app_env).and_return(nil)
|
199
|
+
expect(described_class).to receive(:get_env_var).with('RAILS_ENV').and_return(nil)
|
200
|
+
expect(described_class).to receive(:get_env_var).with('RACK_ENV').and_return(nil)
|
201
|
+
expect(described_class).to receive(:get_env_var).with('APP_ENV').and_return('dwarf_env')
|
202
|
+
}
|
203
|
+
its(:env) { should == 'dwarf_env' }
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
describe '.get_env_var' do
|
208
|
+
before { ENV['DWARF'] = 'little dwarf' }
|
209
|
+
it { described_class.get_env_var('DWARF').should == 'little dwarf'}
|
210
|
+
it { described_class.get_env_var('IS_DWARF').should be_nil}
|
211
|
+
end
|
212
|
+
|
213
|
+
describe '.get_rails' do
|
214
|
+
context 'when defined' do
|
215
|
+
before {
|
216
|
+
Object.const_set(:Rails, Module.new)
|
217
|
+
}
|
218
|
+
after {
|
219
|
+
Object.send(:remove_const, :Rails)
|
220
|
+
}
|
221
|
+
it {
|
222
|
+
described_class.get_rails.should be_kind_of(Module)
|
223
|
+
}
|
224
|
+
end
|
225
|
+
context 'when not defined' do
|
226
|
+
it { described_class.get_rails.should be_nil }
|
227
|
+
end
|
228
|
+
end
|
181
229
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,11 +1,19 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
require 'coveralls'
|
3
|
+
|
4
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
5
|
+
SimpleCov::Formatter::HTMLFormatter,
|
6
|
+
Coveralls::SimpleCov::Formatter
|
7
|
+
]
|
8
|
+
SimpleCov.start do
|
9
|
+
add_filter '/spec/'
|
10
|
+
end
|
11
|
+
|
1
12
|
require 'rubygems'
|
2
13
|
require 'bundler/setup'
|
3
14
|
|
4
15
|
require 'a9n'
|
5
16
|
|
6
|
-
require 'coveralls'
|
7
|
-
Coveralls.wear!
|
8
|
-
|
9
17
|
RSpec.configure do |config|
|
10
18
|
config.order = "random"
|
11
19
|
config.color_enabled = true
|
data/spec/struct_spec.rb
CHANGED