a9n 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/Gemfile +1 -1
- data/README.md +12 -10
- data/lib/a9n.rb +5 -5
- data/lib/a9n/capistrano.rb +11 -0
- data/lib/a9n/struct.rb +2 -2
- data/lib/a9n/version.rb +1 -1
- data/spec/a9n_spec.rb +30 -16
- data/spec/struct_spec.rb +14 -11
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1278accbf3b20ef8dcf2084995996dbaa1bdabda
|
4
|
+
data.tar.gz: d444fa5ca535f636c4d0eefb03895d3bf12813da
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71e3c6444b5418cf69547a9e81cd88dcefd6d346648268de14f2adf045f0920100865041cd0f7637c25f5d2fe376036b39c4b3be24df2ddb8729531bcee02d1b
|
7
|
+
data.tar.gz: 5b924cb72e0a6d6813056ab6ef43e1b3a07ac4eb5c3615ae74c26834b3bc8ce0938fabbe0d07eeeaf06a23b94708255cf8ad192114405d40c00458a7bd345090
|
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 extra configuration in ruby/rails apps. Supports Rails 2.x, 3.x, 4.x and Ruby 1.9, 2.0.
|
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.
|
14
14
|
Ruby 1.8 is not supported in version 0.1.2 and higher.
|
15
15
|
|
16
16
|
## Installation
|
@@ -28,7 +28,7 @@ directory. When none fo these files exists, `A9n::MissingConfigurationFile`
|
|
28
28
|
exception is thrown.
|
29
29
|
If both file exist, content of `configuration.yml` is validated. It means that
|
30
30
|
all keys existing in example file must exist in base file - in case of missing
|
31
|
-
keys`A9n::MissingConfigurationVariables` is thrown with information about
|
31
|
+
keys`A9n::MissingConfigurationVariables` is thrown with information about
|
32
32
|
missing keys.
|
33
33
|
|
34
34
|
Set application root and load configuration by adding to your `application.rb` or `environment.rb` right
|
@@ -45,7 +45,7 @@ you may need to tell it A9n:
|
|
45
45
|
|
46
46
|
## Usage
|
47
47
|
|
48
|
-
You can access any variable defined in configuration files but delegating it to
|
48
|
+
You can access any variable defined in configuration files but delegating it to
|
49
49
|
`A9n`. E.g:
|
50
50
|
|
51
51
|
defaults:
|
@@ -62,16 +62,18 @@ is accessible by:
|
|
62
62
|
|
63
63
|
## Custom and multiple configuration files
|
64
64
|
|
65
|
-
If you need to load config from custom files (e.g `config/mongo.yml` and `config/
|
66
|
-
|
67
|
-
A9n.load('mongo.yml', 'other.yml')
|
68
|
-
|
69
|
-
and the configuration is availble under `mongo` and `
|
65
|
+
If you need to load config from custom files (e.g `config/mongo.yml`, `config/other.yml` and `config/custom_dir/extra.yml`), add:
|
66
|
+
|
67
|
+
A9n.load('mongo.yml', 'other.yml', 'custom_dir/extra')
|
68
|
+
|
69
|
+
and the configuration is availble under `mongo`, `other` and `extra` scopes:
|
70
70
|
|
71
71
|
A9n.mongo.varname
|
72
|
-
|
72
|
+
|
73
73
|
A9n.other.varname
|
74
|
-
|
74
|
+
|
75
|
+
A9n.extra.varname
|
76
|
+
|
75
77
|
## Contributing
|
76
78
|
|
77
79
|
1. Fork it
|
data/lib/a9n.rb
CHANGED
@@ -10,8 +10,8 @@ module A9n
|
|
10
10
|
class MissingConfigurationVariables < StandardError; end
|
11
11
|
class NoSuchConfigurationVariable < StandardError; end
|
12
12
|
|
13
|
-
DEFAULT_FILE = 'configuration.yml'
|
14
13
|
DEFAULT_SCOPE = :configuration
|
14
|
+
DEFAULT_FILE = "#{DEFAULT_SCOPE}.yml"
|
15
15
|
|
16
16
|
class << self
|
17
17
|
def env
|
@@ -109,6 +109,10 @@ module A9n
|
|
109
109
|
ENV[name]
|
110
110
|
end
|
111
111
|
|
112
|
+
def var_name_for(file)
|
113
|
+
:"@#{file.to_s.split('/').last.split('.').first}"
|
114
|
+
end
|
115
|
+
|
112
116
|
private
|
113
117
|
|
114
118
|
def verify!(example, local)
|
@@ -117,9 +121,5 @@ module A9n
|
|
117
121
|
raise MissingConfigurationVariables.new("Following variables are missing in your configuration file: #{missing_keys.join(",")}")
|
118
122
|
end
|
119
123
|
end
|
120
|
-
|
121
|
-
def var_name_for(file)
|
122
|
-
:"@#{file.to_s.split('.').first}"
|
123
|
-
end
|
124
124
|
end
|
125
125
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
Capistrano::Configuration.instance.load do
|
2
|
+
after "deploy:update_code", "a9n:copy_stage_config"
|
3
|
+
|
4
|
+
namespace :a9n do
|
5
|
+
desc "Copy stage configuration to base file."
|
6
|
+
task :copy_stage_config, roles: :app do
|
7
|
+
run "cp #{fetch(:release_path)}/config/configuration.yml.#{fetch(:stage)} #{fetch(:release_path)}/config/configuration.yml"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
data/lib/a9n/struct.rb
CHANGED
data/lib/a9n/version.rb
CHANGED
data/spec/a9n_spec.rb
CHANGED
@@ -7,7 +7,7 @@ describe A9n do
|
|
7
7
|
expect(described_class).to receive(:get_rails).and_return(nil)
|
8
8
|
}
|
9
9
|
specify {
|
10
|
-
described_class.local_app.
|
10
|
+
expect(described_class.local_app).to be_nil
|
11
11
|
}
|
12
12
|
end
|
13
13
|
|
@@ -15,7 +15,7 @@ describe A9n do
|
|
15
15
|
let(:local_app) { double(env: 'test', root: '/apps/a9n') }
|
16
16
|
before { described_class.local_app = local_app }
|
17
17
|
|
18
|
-
specify { described_class.local_app.
|
18
|
+
specify { expect(described_class.local_app).to eq(local_app) }
|
19
19
|
end
|
20
20
|
|
21
21
|
after { described_class.local_app = nil }
|
@@ -30,13 +30,13 @@ describe A9n do
|
|
30
30
|
described_class.root = '/home/knapo/workspace/a9n'
|
31
31
|
}
|
32
32
|
specify {
|
33
|
-
described_class.root.
|
33
|
+
expect(described_class.root).to eq(Pathname.new('/home/knapo/workspace/a9n'))
|
34
34
|
}
|
35
35
|
end
|
36
36
|
|
37
37
|
context 'with local app path' do
|
38
38
|
specify {
|
39
|
-
described_class.root.
|
39
|
+
expect(described_class.root).to eq('/apps/a9n')
|
40
40
|
}
|
41
41
|
end
|
42
42
|
|
@@ -80,9 +80,9 @@ describe A9n do
|
|
80
80
|
expect(described_class).to receive(:verify!).never
|
81
81
|
end
|
82
82
|
it 'raises expection' do
|
83
|
-
|
83
|
+
expect {
|
84
84
|
described_class.load
|
85
|
-
}.
|
85
|
+
}.to raise_error(described_class::MissingConfigurationData)
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
@@ -215,13 +215,13 @@ describe A9n do
|
|
215
215
|
end
|
216
216
|
|
217
217
|
it 'has symbolized keys' do
|
218
|
-
subject.keys.first.
|
219
|
-
subject[:hash_dwarf].
|
220
|
-
subject[:hash_dwarf].keys.first.
|
218
|
+
expect(subject.keys.first).to be_kind_of(Symbol)
|
219
|
+
expect(subject[:hash_dwarf]).to be_kind_of(Hash)
|
220
|
+
expect(subject[:hash_dwarf].keys.first).to be_kind_of(Symbol)
|
221
221
|
end
|
222
222
|
|
223
223
|
it 'parses erb' do
|
224
|
-
subject[:erb_dwarf].
|
224
|
+
expect(subject[:erb_dwarf]).to eq('erbized dwarf')
|
225
225
|
end
|
226
226
|
end
|
227
227
|
|
@@ -242,7 +242,11 @@ describe A9n do
|
|
242
242
|
expect(described_class).to receive(:local_app).and_return(double(env: 'dwarf_env')).exactly(3).times
|
243
243
|
expect(described_class).to receive(:get_env_var).never
|
244
244
|
}
|
245
|
-
|
245
|
+
|
246
|
+
describe '#env' do
|
247
|
+
subject { super().env }
|
248
|
+
it { should == 'dwarf_env' }
|
249
|
+
end
|
246
250
|
end
|
247
251
|
|
248
252
|
context "when APP_ENV is set" do
|
@@ -252,14 +256,18 @@ describe A9n do
|
|
252
256
|
expect(described_class).to receive(:get_env_var).with('RACK_ENV').and_return(nil)
|
253
257
|
expect(described_class).to receive(:get_env_var).with('APP_ENV').and_return('dwarf_env')
|
254
258
|
}
|
255
|
-
|
259
|
+
|
260
|
+
describe '#env' do
|
261
|
+
subject { super().env }
|
262
|
+
it { should == 'dwarf_env' }
|
263
|
+
end
|
256
264
|
end
|
257
265
|
end
|
258
266
|
|
259
267
|
describe '.get_env_var' do
|
260
268
|
before { ENV['DWARF'] = 'little dwarf' }
|
261
|
-
it { described_class.get_env_var('DWARF').
|
262
|
-
it { described_class.get_env_var('IS_DWARF').
|
269
|
+
it { expect(described_class.get_env_var('DWARF')).to eq('little dwarf')}
|
270
|
+
it { expect(described_class.get_env_var('IS_DWARF')).to be_nil}
|
263
271
|
end
|
264
272
|
|
265
273
|
describe '.get_rails' do
|
@@ -271,11 +279,17 @@ describe A9n do
|
|
271
279
|
Object.send(:remove_const, :Rails)
|
272
280
|
}
|
273
281
|
it {
|
274
|
-
described_class.get_rails.
|
282
|
+
expect(described_class.get_rails).to be_kind_of(Module)
|
275
283
|
}
|
276
284
|
end
|
277
285
|
context 'when not defined' do
|
278
|
-
it { described_class.get_rails.
|
286
|
+
it { expect(described_class.get_rails).to be_nil }
|
279
287
|
end
|
280
288
|
end
|
289
|
+
|
290
|
+
describe '.var_name_for' do
|
291
|
+
it { expect(described_class.var_name_for(:configuration)).to eq(:@configuration) }
|
292
|
+
it { expect(described_class.var_name_for('configuration.yml')).to eq(:@configuration) }
|
293
|
+
it { expect(described_class.var_name_for('custom_dir/extra.yml')).to eq(:@extra) }
|
294
|
+
end
|
281
295
|
end
|
data/spec/struct_spec.rb
CHANGED
@@ -11,41 +11,44 @@ describe A9n::Struct do
|
|
11
11
|
})
|
12
12
|
}
|
13
13
|
|
14
|
-
|
14
|
+
describe '#keys' do
|
15
|
+
subject { super().keys }
|
16
|
+
it { should == [:non_empty_dwarf, :nil_dwarf, :false_dwarf, :true_dwarf, :hash_dwarf] }
|
17
|
+
end
|
15
18
|
|
16
19
|
it 'gets non-empty value' do
|
17
|
-
subject.non_empty_dwarf.
|
20
|
+
expect(subject.non_empty_dwarf).to eq('dwarf')
|
18
21
|
end
|
19
22
|
|
20
23
|
it 'gets nil value' do
|
21
|
-
subject.nil_dwarf.
|
24
|
+
expect(subject.nil_dwarf).to eq(nil)
|
22
25
|
end
|
23
26
|
|
24
27
|
it 'gets true value' do
|
25
|
-
subject.true_dwarf.
|
28
|
+
expect(subject.true_dwarf).to eq(true)
|
26
29
|
end
|
27
|
-
|
30
|
+
|
28
31
|
it 'gets false value' do
|
29
|
-
subject.false_dwarf.
|
32
|
+
expect(subject.false_dwarf).to eq(false)
|
30
33
|
end
|
31
34
|
|
32
35
|
it 'gets hash value' do
|
33
|
-
subject.hash_dwarf.
|
36
|
+
expect(subject.hash_dwarf).to be_kind_of(Hash)
|
34
37
|
end
|
35
38
|
|
36
39
|
it 'raises exception when value not exists' do
|
37
|
-
expect {
|
40
|
+
expect {
|
38
41
|
subject.non_existing_dwarf
|
39
42
|
}.to raise_error(A9n::NoSuchConfigurationVariable)
|
40
43
|
end
|
41
44
|
|
42
45
|
describe '#fetch' do
|
43
46
|
it 'return non empty value' do
|
44
|
-
subject.fetch(:non_empty_dwarf).
|
47
|
+
expect(subject.fetch(:non_empty_dwarf)).to eq('dwarf')
|
45
48
|
end
|
46
49
|
|
47
50
|
it 'not returns nil for non existing value' do
|
48
|
-
subject.fetch(:non_existing_dwarf).
|
51
|
+
expect(subject.fetch(:non_existing_dwarf)).to eq(nil)
|
49
52
|
end
|
50
53
|
end
|
51
|
-
end
|
54
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: a9n
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Krzysztof Knapik
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Simple tool for managing extra configuration in ruby/rails apps
|
14
14
|
email:
|
@@ -26,6 +26,7 @@ files:
|
|
26
26
|
- Rakefile
|
27
27
|
- a9n.gemspec
|
28
28
|
- lib/a9n.rb
|
29
|
+
- lib/a9n/capistrano.rb
|
29
30
|
- lib/a9n/core_ext/hash.rb
|
30
31
|
- lib/a9n/struct.rb
|
31
32
|
- lib/a9n/version.rb
|