a9n 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cb78fbff3f0313e316677658597f0143d5688835
4
- data.tar.gz: ec4ee59ac801e019236d895674b325ac0b720483
3
+ metadata.gz: 90f0d9378a0371006614053fd5f2ba3add41dd36
4
+ data.tar.gz: e2d2b46d4acc96d2fadf7e83ee13e396b9daa988
5
5
  SHA512:
6
- metadata.gz: 6325f3fbad2cc18a3d8eb78cde05aebf3c3a0ea62f7a0c1b4e4c2b27e2901919f292c8d268a90319baf053235fcc0055e46aea595a1be764c896b0339fcd88dd
7
- data.tar.gz: d0d1228d3b001208f1296f2f6e9468173acac35169cf34810dce9fd303c811ffd303fb9027db19a51d411c3207ba0d8108c90818654f7323daa3bd2a9d07361f
6
+ metadata.gz: 898bc6b5f725ce86e9323a528979c0fbf082627717b30786a8e1625d1f6b0c838964b03bdba3052526265fe5ecf8aae10f2d77d93fefb64df5ae330aca316a57
7
+ data.tar.gz: e5e42e3571bfb95ac3a5d308a40639a0d99d8d6e721384ba250fe56297e915c16adee00877e3131c7469f24854129b97791e35f9f76386485992d8fab5e0a30d
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.1.5@a9n
1
+ 2.2.2@a9n
data/.travis.yml CHANGED
@@ -1,8 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.0.0
4
- - 2.1.5
5
- - 2.2.0
4
+ - 2.1.6
5
+ - 2.2.2
6
6
  addons:
7
7
  code_climate:
8
8
  repo_token: 9aa2aa2432639c57772b6917ad9da468709e5536b75617575b02b35201a2eaf8
data/lib/a9n/ext/hash.rb CHANGED
@@ -1,21 +1,29 @@
1
1
  module A9n
2
2
  class HashExt
3
3
  class << self
4
- # Hash#deep_symbolize_keys
5
- # based on
6
- # https://github.com/svenfuchs/i18n/blob/master/lib/i18n/core_ext/hash.rb
7
- def deep_symbolize_keys(hash)
8
- hash.inject({}) { |result, (key, value)|
9
- value = deep_symbolize_keys(value) if value.is_a?(::Hash)
10
- result[(key.to_sym rescue key) || key] = value
4
+ def deep_prepare(hash)
5
+ hash.inject({}) do |result, (key, value)|
6
+ result[(key.to_sym rescue key)] = get_value(key, value)
11
7
  result
12
- }
8
+ end
13
9
  end
14
10
 
15
11
  def merge(*items)
16
12
  return nil if items.compact.empty?
17
13
  items.compact.inject({}){|sum, item| sum.merge!(item)}
18
14
  end
15
+
16
+ private
17
+
18
+ def get_value(key, value)
19
+ if value.is_a?(::Hash)
20
+ deep_prepare(value)
21
+ elsif value.is_a?(Symbol) && value == :env
22
+ ENV[key.to_s.upcase]
23
+ else
24
+ value
25
+ end
26
+ end
19
27
  end
20
28
  end
21
29
  end
data/lib/a9n/loader.rb CHANGED
@@ -44,7 +44,7 @@ module A9n
44
44
 
45
45
  def prepare_yml_scope(yml, env_scope)
46
46
  if yml[env_scope].is_a?(::Hash)
47
- A9n::HashExt.deep_symbolize_keys(yml[env_scope])
47
+ A9n::HashExt.deep_prepare(yml[env_scope])
48
48
  else
49
49
  nil
50
50
  end
data/lib/a9n/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module A9n
2
- VERSION = "0.4.2"
2
+ VERSION = "0.4.3"
3
3
  end
@@ -13,15 +13,15 @@ describe A9n::Loader do
13
13
  end
14
14
 
15
15
  describe "#load" do
16
- let(:example_config) {
16
+ let(:example_config) do
17
17
  { app_url: "http://127.0.0.1:3000", api_key: "example1234" }
18
- }
19
- let(:local_config) {
18
+ end
19
+
20
+ let(:local_config) do
20
21
  { app_host: "127.0.0.1:3000", api_key: "local1234" }
21
- }
22
- let(:env){
23
- "tropical"
24
- }
22
+ end
23
+
24
+ let(:env) { "tropical" }
25
25
  let(:config) { subject.get }
26
26
 
27
27
  context "when no configuration file exists" do
@@ -122,7 +122,13 @@ describe A9n::Loader do
122
122
  end
123
123
 
124
124
  before do
125
- ENV["DWARF"] = "erbized dwarf"
125
+ ENV["ERB_DWARF"] = "erbized dwarf"
126
+ ENV["DWARF_PASSWORD"] = "dwarf123"
127
+ end
128
+
129
+ after do
130
+ ENV["ERB_DWARF"] = nil
131
+ ENV["DWARF_PASSWORD"] = nil
126
132
  end
127
133
 
128
134
  context "when file has erb extension" do
@@ -150,6 +156,11 @@ describe A9n::Loader do
150
156
  it "parses erb" do
151
157
  expect(subject[:erb_dwarf]).to eq("erbized dwarf")
152
158
  end
159
+
160
+ it "gets valus from ENV" do
161
+ p subject
162
+ expect(subject[:dwarf_password]).to eq("dwarf123")
163
+ end
153
164
  end
154
165
 
155
166
  context "having no env and only defaults data" do
@@ -1,12 +1,13 @@
1
1
  defaults:
2
2
  default_dwarf: "default dwarf"
3
3
  overriden_dwarf: "not yet overriden dwarf"
4
+ erb_dwarf: "<%= ENV['ERB_DWARF'] %>"
5
+ dwarf_password: :env
4
6
  development:
5
7
  nil_dwarf: ~
6
8
  false_dwarf: false
7
9
  true_dwarf: true
8
10
  string_dwarf: "dwarf"
9
- erb_dwarf: "<%= ENV['DWARF'] %>"
10
11
  overriden_dwarf: "already overriden dwarf"
11
12
  hash_dwarf:
12
13
  dwarf_1: "hello 1"
@@ -16,7 +17,6 @@ test:
16
17
  false_dwarf: false
17
18
  true_dwarf: true
18
19
  string_dwarf: "dwarf"
19
- erb_dwarf: "<%= ENV['DWARF'] %>"
20
20
  overriden_dwarf: "already overriden dwarf"
21
21
  hash_dwarf:
22
22
  dwarf_1: "hello 1"
@@ -1,12 +1,13 @@
1
1
  defaults:
2
2
  default_dwarf: "example default dwarf"
3
3
  overriden_dwarf: "example not yet overriden dwarf"
4
+ erb_dwarf: "<%= ENV['ERB_DWARF'] %>"
5
+ dwarf_password: :env
4
6
  development:
5
7
  nil_dwarf: ~
6
8
  false_dwarf: false
7
9
  true_dwarf: true
8
10
  string_dwarf: "dwarf"
9
- erb_dwarf: "<%= ENV['DWARF'] %>"
10
11
  overriden_dwarf: "example already overriden dwarf"
11
12
  hash_dwarf:
12
13
  dwarf_1: "hello 1"
@@ -16,7 +17,6 @@ test:
16
17
  false_dwarf: false
17
18
  true_dwarf: true
18
19
  string_dwarf: "dwarf"
19
- erb_dwarf: "<%= ENV['DWARF'] %>"
20
20
  overriden_dwarf: "example already overriden dwarf"
21
21
  hash_dwarf:
22
22
  dwarf_1: "hello 1"
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.4.2
4
+ version: 0.4.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: 2015-02-24 00:00:00.000000000 Z
11
+ date: 2015-05-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: a9n - ruby/rails apps configuration manager
14
14
  email:
@@ -66,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
66
  version: '0'
67
67
  requirements: []
68
68
  rubyforge_project:
69
- rubygems_version: 2.4.3
69
+ rubygems_version: 2.4.6
70
70
  signing_key:
71
71
  specification_version: 4
72
72
  summary: a9n is a tool to keep ruby/rails apps extra configuration easily maintainable