a9n 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -14,16 +14,18 @@ And then execute:
14
14
 
15
15
  $ bundle
16
16
 
17
- Add `configuration.yml.example` and/or `configuration.yml` file to config directory.
17
+ Add `configuration.yml.example` and/or `configuration.yml` file into the config directory.
18
+ When none fo these files exists, `A9n::MissingConfigurationFile` exception is thrown.
19
+ If both file exists, their content is validated and all keys existing in example file must exist in base file.
18
20
 
19
21
  ## Usage
20
22
 
21
- You can access any variable defined in `configuration.yml` file but delegating it to A9n. E.g:
23
+ You can access any variable defined in configuration files but delegating it to A9n. E.g:
22
24
 
23
25
  production:
24
26
  app_host: 'http://knapo.net'
25
27
 
26
- is accessible by
28
+ is accessible by:
27
29
 
28
30
  A9n.app_host
29
31
 
data/lib/a9n.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'a9n/version'
2
2
  require 'a9n/struct'
3
+ require 'a9n/core_ext/hash'
3
4
 
4
5
  module A9n
5
6
  class ConfigurationNotLoaded < StandardError; end
@@ -46,8 +47,8 @@ module A9n
46
47
  return unless File.exists?(path)
47
48
  yml = YAML.load_file(path)
48
49
 
49
- if yml.key?(self.env)
50
- return yml[self.env]
50
+ if yml[self.env].is_a?(Hash)
51
+ return yml[self.env].deep_symbolize_keys
51
52
  else
52
53
  raise MissingConfigurationData.new("Configuration data for #{self.env} was not found in #{file}")
53
54
  end
@@ -0,0 +1,12 @@
1
+ class Hash
2
+ # Hash#deep_symbolize_keys
3
+ # based on
4
+ # https://github.com/svenfuchs/i18n/blob/master/lib/i18n/core_ext/hash.rb
5
+ def deep_symbolize_keys
6
+ inject({}) { |result, (key, value)|
7
+ value = value.deep_symbolize_keys if value.is_a?(self.class)
8
+ result[(key.to_sym rescue key) || key] = value
9
+ result
10
+ }
11
+ end unless self.method_defined?(:deep_symbolize_keys)
12
+ end
@@ -1,3 +1,3 @@
1
1
  module A9n
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -124,7 +124,14 @@ describe A9n do
124
124
  subject.should be_kind_of(Hash)
125
125
  subject.keys.should_not be_empty
126
126
  end
127
+
128
+ it 'has symbolized keys' do
129
+ subject.keys.first.should be_kind_of(Symbol)
130
+ subject[:hash_dwarf].should be_kind_of(Hash)
131
+ subject[:hash_dwarf].keys.first.should be_kind_of(Symbol)
132
+ end
127
133
  end
134
+
128
135
  context 'and has no data' do
129
136
  let(:env) { 'production' }
130
137
 
@@ -1,5 +1,16 @@
1
1
  development:
2
- app_url: 'http://127.0.0.1:3000'
3
-
2
+ nil_dwarf: ~
3
+ false_dwarf: false
4
+ true_dwarf: true
5
+ string_dwarf: "dwarf"
6
+ hash_dwarf:
7
+ dwarf_1: "hello 1"
8
+ dwarf_2: "hello 2"
4
9
  test:
5
- app_url: 'http://127.0.0.1:3000'
10
+ nil_dwarf: ~
11
+ false_dwarf: false
12
+ true_dwarf: true
13
+ string_dwarf: "dwarf"
14
+ hash_dwarf:
15
+ dwarf_1: "hello 1"
16
+ dwarf_2: "hello 2"
@@ -6,7 +6,8 @@ describe A9n::Struct do
6
6
  :non_empty_dwarf => 'dwarf',
7
7
  :nil_dwarf => nil,
8
8
  :false_dwarf => false,
9
- :true_dwarf => true
9
+ :true_dwarf => true,
10
+ :hash_dwarf => { :dwarf => 'hello' }
10
11
  })
11
12
  }
12
13
 
@@ -26,6 +27,10 @@ describe A9n::Struct do
26
27
  subject.false_dwarf.should == false
27
28
  end
28
29
 
30
+ it 'gets hash value' do
31
+ subject.hash_dwarf.should be_kind_of(Hash)
32
+ end
33
+
29
34
  it 'raises exception when value not exists' do
30
35
  expect {
31
36
  subject.non_existing_dwarf
metadata CHANGED
@@ -1,33 +1,23 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: a9n
3
- version: !ruby/object:Gem::Version
4
- hash: 21
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 5
10
- version: 0.0.5
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Krzysztof Knapik
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-12-07 00:00:00 Z
12
+ date: 2012-12-08 00:00:00.000000000 Z
19
13
  dependencies: []
20
-
21
14
  description: Simple tool for managing app configuration
22
- email:
15
+ email:
23
16
  - knapo@knapo.net
24
17
  executables: []
25
-
26
18
  extensions: []
27
-
28
19
  extra_rdoc_files: []
29
-
30
- files:
20
+ files:
31
21
  - .gitignore
32
22
  - .travis.yml
33
23
  - Gemfile
@@ -36,6 +26,7 @@ files:
36
26
  - Rakefile
37
27
  - a9n.gemspec
38
28
  - lib/a9n.rb
29
+ - lib/a9n/core_ext/hash.rb
39
30
  - lib/a9n/struct.rb
40
31
  - lib/a9n/version.rb
41
32
  - spec/a9n_spec.rb
@@ -44,38 +35,29 @@ files:
44
35
  - spec/struct_spec.rb
45
36
  homepage: https://github.com/knapo/a9n
46
37
  licenses: []
47
-
48
38
  post_install_message:
49
39
  rdoc_options: []
50
-
51
- require_paths:
40
+ require_paths:
52
41
  - lib
53
- required_ruby_version: !ruby/object:Gem::Requirement
42
+ required_ruby_version: !ruby/object:Gem::Requirement
54
43
  none: false
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- hash: 3
59
- segments:
60
- - 0
61
- version: "0"
62
- required_rubygems_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
49
  none: false
64
- requirements:
65
- - - ">="
66
- - !ruby/object:Gem::Version
67
- hash: 3
68
- segments:
69
- - 0
70
- version: "0"
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
71
54
  requirements: []
72
-
73
55
  rubyforge_project:
74
56
  rubygems_version: 1.8.24
75
57
  signing_key:
76
58
  specification_version: 3
77
59
  summary: Simple tool for managing app configuration
78
- test_files:
60
+ test_files:
79
61
  - spec/a9n_spec.rb
80
62
  - spec/fixtures/configuration.yml
81
63
  - spec/spec_helper.rb