a9n 0.2.0 → 0.2.2

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: e369363c79fb9a656521140c1579f784a7e9dc4a
4
- data.tar.gz: cfc947874a96b1884b65200baf180c7f85b5c30d
3
+ metadata.gz: 39c493dd369e2ff7e7ca0fbc67aeb3eb3d2bb4de
4
+ data.tar.gz: 3d15911fbfc65a606fc3f5484b99ca9549fd76fb
5
5
  SHA512:
6
- metadata.gz: 87fe223271b1188c7df2322279456879bf47a6abfb5c97b9d7ca95faf81d13a9fdae9bce28d2fa6df47ad86f5a361660ccc55153ed4904f7bd099408bc819093
7
- data.tar.gz: 4c452ad39305bc59df2c81ab207ee98424e8a80967055caebc6fc035b88432f510a49caaa7621053be67ea62faa40859be50cedf8bdeb48a7d5fce11ac31e1c9
6
+ metadata.gz: d8dfd10661f36985ebbe762c773e329fa4aedcf74fe5c30da08d201e510198d9f8b81e66e4290657e1fb2c4e94c9661c9ae6a3f34854feda9cea581d2168588b
7
+ data.tar.gz: 31d6d95ae6553c7a62b332af9e40fef465395da7b6637452bfaa7a7317a4030ba4ba5c3db44128e465a17942b8469b3ca305a6cb00423834f3df69f8e14591fa
@@ -0,0 +1 @@
1
+ 2.0.0@a9n
@@ -4,5 +4,3 @@ rvm:
4
4
  - 2.0.0
5
5
  - 2.1.1
6
6
  - jruby-19mode
7
- - rbx-2.0.0
8
- - rbx-2.1.1
data/lib/a9n.rb CHANGED
@@ -6,7 +6,6 @@ require "erb"
6
6
 
7
7
  module A9n
8
8
  class ConfigurationNotLoaded < StandardError; end
9
- class MissingConfigurationFile < StandardError; end
10
9
  class MissingConfigurationData < StandardError; end
11
10
  class MissingConfigurationVariables < StandardError; end
12
11
  class NoSuchConfigurationVariable < StandardError; end
@@ -47,46 +46,39 @@ module A9n
47
46
  def load(*files)
48
47
  files = [DEFAULT_FILE] if files.empty?
49
48
  files.map do |file|
50
- env_config = load_env_config(file)
51
- default_config = load_default_config(file)
49
+ default_and_env_config = load_config(file)
52
50
 
53
- whole_config = default_config.merge(env_config)
54
-
55
- instance_variable_set(var_name_for(file), A9n::Struct.new(whole_config))
51
+ instance_variable_set(var_name_for(file), A9n::Struct.new(default_and_env_config))
56
52
  end
57
53
  end
58
54
 
59
- def load_env_config(file)
60
- base = load_yml("config/#{file}.example", env)
61
- local = load_yml("config/#{file}", env)
55
+ def load_config(file)
56
+ env_example = load_yml("config/#{file}.example", env)
57
+ env_local = load_yml("config/#{file}", env)
58
+ default_example = load_yml("config/#{file}.example", "defaults")
59
+ default_local = load_yml("config/#{file}", "defaults")
62
60
 
63
- if base.nil? && local.nil?
64
- raise MissingConfigurationFile.new("Neither config/#{file}.example nor config/#{file} was found")
61
+ if env_example.nil? && env_local.nil? && default_example.nil? && default_local.nil?
62
+ raise MissingConfigurationData.new("Configuration data was not found in neither config/#{file}.example nor config/#{file}")
65
63
  end
66
64
 
67
- if !base.nil? && !local.nil?
68
- verify!(base, local)
69
- end
65
+ example = Hash.merge(default_example, env_example)
66
+ local = Hash.merge( default_local,env_local)
70
67
 
71
- local || base
72
- end
68
+ if !example.nil? && !local.nil?
69
+ verify!(example, local)
70
+ end
73
71
 
74
- def load_default_config(file = "configuration.yml")
75
- data = load_yml("config/#{file}.example", "defaults", false)
76
- data ||= load_yml("config/#{file}", "defaults", false)
77
- data ||= {}
78
- return data
72
+ local || example
79
73
  end
80
74
 
81
- def load_yml(file, env, raise_when_not_found = true)
75
+ def load_yml(file, env)
82
76
  path = File.join(self.root, file)
83
77
  return nil unless File.exists?(path)
84
78
  yml = YAML.load(ERB.new(File.read(path)).result)
85
79
 
86
80
  if yml[env].is_a?(Hash)
87
81
  return yml[env].deep_symbolize_keys
88
- elsif raise_when_not_found
89
- raise MissingConfigurationData.new("Configuration data for #{env} was not found in #{file}")
90
82
  else
91
83
  return nil
92
84
  end
@@ -119,8 +111,8 @@ module A9n
119
111
 
120
112
  private
121
113
 
122
- def verify!(base, local)
123
- missing_keys = base.keys - local.keys
114
+ def verify!(example, local)
115
+ missing_keys = example.keys - local.keys
124
116
  if missing_keys.any?
125
117
  raise MissingConfigurationVariables.new("Following variables are missing in your configuration file: #{missing_keys.join(",")}")
126
118
  end
@@ -1,5 +1,5 @@
1
1
  class Hash
2
- # Hash#deep_symbolize_keys
2
+ # Hash#deep_symbolize_keys
3
3
  # based on
4
4
  # https://github.com/svenfuchs/i18n/blob/master/lib/i18n/core_ext/hash.rb
5
5
  def deep_symbolize_keys
@@ -9,4 +9,9 @@ class Hash
9
9
  result
10
10
  }
11
11
  end unless self.method_defined?(:deep_symbolize_keys)
12
- end
12
+
13
+ def self.merge(*items)
14
+ return nil if items.compact.empty?
15
+ items.compact.inject({}){|sum, item| sum.merge!(item)}
16
+ end
17
+ end
@@ -1,3 +1,3 @@
1
1
  module A9n
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -75,14 +75,14 @@ describe A9n do
75
75
  before do
76
76
  expect(described_class).to receive(:load_yml).with("config/#{base_file}.example", env).and_return(nil)
77
77
  expect(described_class).to receive(:load_yml).with("config/#{base_file}", env).and_return(nil)
78
- expect(described_class).to receive(:load_yml).with("config/#{base_file}.example", 'defaults', false).never
79
- expect(described_class).to receive(:load_yml).with("config/#{base_file}", 'defaults', false).never
78
+ expect(described_class).to receive(:load_yml).with("config/#{base_file}.example", 'defaults').and_return(nil)
79
+ expect(described_class).to receive(:load_yml).with("config/#{base_file}", 'defaults').and_return(nil)
80
80
  expect(described_class).to receive(:verify!).never
81
81
  end
82
82
  it 'raises expection' do
83
83
  lambda {
84
84
  described_class.load
85
- }.should raise_error(described_class::MissingConfigurationFile)
85
+ }.should raise_error(described_class::MissingConfigurationData)
86
86
  end
87
87
  end
88
88
 
@@ -90,8 +90,8 @@ describe A9n do
90
90
  before do
91
91
  expect(described_class).to receive(:load_yml).with("config/#{base_file}.example", env).and_return(base_sample_config)
92
92
  expect(described_class).to receive(:load_yml).with("config/#{base_file}", env).and_return(nil)
93
- expect(described_class).to receive(:load_yml).with("config/#{base_file}.example", 'defaults', false).and_return(base_default_config)
94
- expect(described_class).to receive(:load_yml).with("config/#{base_file}", 'defaults', false).never
93
+ expect(described_class).to receive(:load_yml).with("config/#{base_file}.example", 'defaults').and_return(base_default_config)
94
+ expect(described_class).to receive(:load_yml).with("config/#{base_file}", 'defaults').and_return(nil)
95
95
 
96
96
  expect(described_class).to receive(:verify!).never
97
97
  described_class.load
@@ -113,8 +113,8 @@ describe A9n do
113
113
  before do
114
114
  expect(described_class).to receive(:load_yml).with("config/#{base_file}.example", env).and_return(nil)
115
115
  expect(described_class).to receive(:load_yml).with("config/#{base_file}", env).and_return(local_sample_config)
116
- expect(described_class).to receive(:load_yml).with("config/#{base_file}.example", 'defaults', false).and_return(nil)
117
- expect(described_class).to receive(:load_yml).with("config/#{base_file}", 'defaults', false).and_return(local_default_config)
116
+ expect(described_class).to receive(:load_yml).with("config/#{base_file}.example", 'defaults').and_return(nil)
117
+ expect(described_class).to receive(:load_yml).with("config/#{base_file}", 'defaults').and_return(local_default_config)
118
118
  expect(described_class).to receive(:verify!).never
119
119
  described_class.load
120
120
  end
@@ -132,8 +132,8 @@ describe A9n do
132
132
  before do
133
133
  expect(described_class).to receive(:load_yml).with("config/#{base_file}.example", env).and_return(base_sample_config)
134
134
  expect(described_class).to receive(:load_yml).with("config/#{base_file}", env).and_return(base_sample_config)
135
- expect(described_class).to receive(:load_yml).with("config/#{base_file}.example", 'defaults', false).and_return(nil)
136
- expect(described_class).to receive(:load_yml).with("config/#{base_file}", 'defaults', false).and_return(nil)
135
+ expect(described_class).to receive(:load_yml).with("config/#{base_file}.example", 'defaults').and_return(nil)
136
+ expect(described_class).to receive(:load_yml).with("config/#{base_file}", 'defaults').and_return(nil)
137
137
  described_class.load
138
138
  end
139
139
 
@@ -151,8 +151,8 @@ describe A9n do
151
151
  before do
152
152
  expect(described_class).to receive(:load_yml).with("config/#{base_file}.example", env).and_return(base_sample_config)
153
153
  expect(described_class).to receive(:load_yml).with("config/#{base_file}", env).and_return(local_sample_config)
154
- expect(described_class).to receive(:load_yml).with("config/#{base_file}.example", 'defaults', false).never
155
- expect(described_class).to receive(:load_yml).with("config/#{base_file}", 'defaults', false).never
154
+ expect(described_class).to receive(:load_yml).with("config/#{base_file}.example", 'defaults').and_return(nil)
155
+ expect(described_class).to receive(:load_yml).with("config/#{base_file}", 'defaults').and_return(nil)
156
156
  end
157
157
  it 'raises expection' do
158
158
  expect {
@@ -166,8 +166,8 @@ describe A9n do
166
166
  before do
167
167
  expect(described_class).to receive(:load_yml).with("config/#{extra_file}.example", env).and_return(base_sample_config)
168
168
  expect(described_class).to receive(:load_yml).with("config/#{extra_file}", env).and_return(nil)
169
- expect(described_class).to receive(:load_yml).with("config/#{extra_file}.example", 'defaults', false).and_return(base_default_config)
170
- expect(described_class).to receive(:load_yml).with("config/#{extra_file}", 'defaults', false).never
169
+ expect(described_class).to receive(:load_yml).with("config/#{extra_file}.example", 'defaults').and_return(base_default_config)
170
+ expect(described_class).to receive(:load_yml).with("config/#{extra_file}", 'defaults').and_return(nil)
171
171
 
172
172
  expect(described_class).to receive(:verify!).never
173
173
  described_class.load('mongo.yml')
@@ -227,12 +227,7 @@ describe A9n do
227
227
 
228
228
  context 'and has no data' do
229
229
  let(:env) { 'production' }
230
-
231
- it 'raises expection' do
232
- expect {
233
- subject
234
- }.to raise_error(described_class::MissingConfigurationData)
235
- end
230
+ it { should be_nil }
236
231
  end
237
232
  end
238
233
  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.0
4
+ version: 0.2.2
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-03-12 00:00:00.000000000 Z
11
+ date: 2014-03-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Simple tool for managing extra configuration in ruby/rails apps
14
14
  email:
@@ -18,6 +18,7 @@ extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
20
  - .gitignore
21
+ - .ruby-version
21
22
  - .travis.yml
22
23
  - Gemfile
23
24
  - LICENSE
@@ -52,7 +53,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
52
53
  version: '0'
53
54
  requirements: []
54
55
  rubyforge_project:
55
- rubygems_version: 2.1.11
56
+ rubygems_version: 2.2.2
56
57
  signing_key:
57
58
  specification_version: 4
58
59
  summary: a9n is a simple tool for managing extra configuration in ruby/rails apps