a9n 0.4.6 → 0.4.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 044172d147418c1f64d54e328192b4b9dbb06bd5
4
- data.tar.gz: 2b2f7135afc4dc3805a0d14bf405547bfee1c0ec
3
+ metadata.gz: 6c42b5f9aaf76bc887465a6fdd0a79ee562d9295
4
+ data.tar.gz: f0451023f9ef4e7868040ed028ca0c7c375a6672
5
5
  SHA512:
6
- metadata.gz: fb2d5778aa099e48696f1ba15190efcbf643e047aa9f365aee02d0d9ef7d3aedb10b062f192b67829f18043624b86783797dd49c27d128dd2c6a4e86ea5fde5a
7
- data.tar.gz: 267caee0c0c17a25d1dfbc9045fda30ce94903a370b672d68af413350c151f8ccbed519d19fdb4bbbc5ee1126f44795d96495e5cc1c63840271ae0755f0e8607
6
+ metadata.gz: 2b3d29df86f51828f13546861bb0839424a14606d6724798ae7893c43aa06200899693e6267d538f0167d9a062c88776e2721c1363d8879b2eea50e2860b673c
7
+ data.tar.gz: d972cf3270b4b97f87aae0f7806b4b6c2fbd5f917150c4a80ec8b6686f3eb5a7250f8bf68be1ef0f77189110cc908c2e290f9e77104f1ccca50a5522a3d827c8
data/README.md CHANGED
@@ -29,7 +29,7 @@ directory. When none fo these files exists, `A9n::MissingConfigurationFile`
29
29
  exception is thrown.
30
30
  If both file exist, content of `configuration.yml` is validated. It means that
31
31
  all keys existing in example file must exist in local file - in case of missing
32
- keys `A9n::MissingConfigurationVariables` is thrown with the explanation what is missing.
32
+ keys `A9n::MissingConfigurationVariablesError` is thrown with the explanation what is missing.
33
33
 
34
34
  Set application root and load configuration by adding to your `application.rb` or `environment.rb` right
35
35
  after budler requires:
data/a9n.gemspec CHANGED
@@ -14,4 +14,6 @@ Gem::Specification.new do |gem|
14
14
  gem.name = "a9n"
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = A9n::VERSION
17
+
18
+ gem.required_ruby_version = ">= 2.0"
17
19
  end
data/lib/a9n.rb CHANGED
@@ -9,10 +9,11 @@ require "erb"
9
9
  module A9n
10
10
  extend SingleForwardable
11
11
 
12
- class ConfigurationNotLoaded < StandardError; end
13
- class MissingConfigurationData < StandardError; end
14
- class MissingConfigurationVariables < StandardError; end
15
- class NoSuchConfigurationVariable < StandardError; end
12
+ class ConfigurationNotLoadedError < StandardError; end
13
+ class MissingConfigurationDataError < StandardError; end
14
+ class MissingConfigurationVariablesError < StandardError; end
15
+ class NoSuchConfigurationVariableError < StandardError; end
16
+ class MissingEnvVariableError < StandardError; end
16
17
 
17
18
  EXTENSION_LIST = "{yml,yml.erb,yml.example,yml.erb.example}"
18
19
 
@@ -49,7 +50,8 @@ module A9n
49
50
  defined?(Rails) ? Rails : nil
50
51
  end
51
52
 
52
- def get_env_var(name)
53
+ def get_env_var(name, strict = false)
54
+ raise MissingEnvVariableError.new(name) if strict && !ENV.key?(name)
53
55
  ENV[name]
54
56
  end
55
57
 
data/lib/a9n/ext/hash.rb CHANGED
@@ -19,7 +19,7 @@ module A9n
19
19
  if value.is_a?(::Hash)
20
20
  deep_prepare(value, scope)
21
21
  elsif value.is_a?(Symbol) && value == :env
22
- ENV[scope.full_key_name(key).upcase]
22
+ A9n.get_env_var(scope.env_key_name(key), true)
23
23
  else
24
24
  value
25
25
  end
data/lib/a9n/loader.rb CHANGED
@@ -22,7 +22,7 @@ module A9n
22
22
  example_config = self.class.load_yml(example_file, scope, env)
23
23
 
24
24
  if local_config.nil? && example_config.nil?
25
- raise A9n::MissingConfigurationData.new("Configuration data for *#{env}* env was not found in neither *#{example_file}* nor *#{local_file}*")
25
+ raise A9n::MissingConfigurationDataError.new("Configuration data for *#{env}* env was not found in neither *#{example_file}* nor *#{local_file}*")
26
26
  end
27
27
 
28
28
  if !local_config.nil? && !example_config.nil?
@@ -57,7 +57,7 @@ module A9n
57
57
  def verify!(local, example)
58
58
  missing_keys = example.keys - local.keys
59
59
  if missing_keys.any?
60
- raise A9n::MissingConfigurationVariables.new("Following variables are missing in #{local_file} file: #{missing_keys.join(",")}")
60
+ raise A9n::MissingConfigurationVariablesError.new("Following variables are missing in #{local_file} file: #{missing_keys.join(",")}")
61
61
  end
62
62
  end
63
63
  end
data/lib/a9n/scope.rb CHANGED
@@ -12,8 +12,8 @@ module A9n
12
12
  name == MAIN_NAME
13
13
  end
14
14
 
15
- def full_key_name(key)
16
- main? ? key : "#{name}_#{key}"
15
+ def env_key_name(key)
16
+ (main? ? key : "#{name}_#{key}").upcase
17
17
  end
18
18
 
19
19
  def self.form_file_path(path)
data/lib/a9n/struct.rb CHANGED
@@ -13,7 +13,7 @@ module A9n
13
13
  end
14
14
 
15
15
  def method_missing(name, *args)
16
- raise NoSuchConfigurationVariable.new(name)
16
+ raise NoSuchConfigurationVariableError.new(name)
17
17
  end
18
18
  end
19
19
  end
data/lib/a9n/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module A9n
2
- VERSION = "0.4.6"
2
+ VERSION = "0.4.7"
3
3
  end
@@ -5,6 +5,8 @@ RSpec.describe A9n do
5
5
 
6
6
  before do
7
7
  clean_singleton(subject)
8
+ ENV["ERB_DWARF"] = "erbized dwarf"
9
+ ENV["DWARF_PASSWORD"] = "dwarf123"
8
10
  ENV["MANDRILL_API_KEY"] = "ASDF1234"
9
11
  ENV["API_KEY"] = "XYZ999"
10
12
  subject.app = double(env: env)
@@ -34,7 +36,7 @@ RSpec.describe A9n do
34
36
  end
35
37
 
36
38
  it do
37
- expect { subject.invalid }.to raise_error(A9n::NoSuchConfigurationVariable)
39
+ expect { subject.invalid }.to raise_error(A9n::NoSuchConfigurationVariableError)
38
40
  end
39
41
 
40
42
  it do
@@ -228,7 +228,7 @@ RSpec.describe A9n do
228
228
 
229
229
  it do
230
230
  expect(subject.storage).to be_empty
231
- expect { subject.whatever }.to raise_error(A9n::NoSuchConfigurationVariable)
231
+ expect { subject.whatever }.to raise_error(A9n::NoSuchConfigurationVariableError)
232
232
  end
233
233
  end
234
234
 
@@ -239,7 +239,7 @@ RSpec.describe A9n do
239
239
  end
240
240
 
241
241
  it do
242
- expect { subject.whatever }.to raise_error(A9n::NoSuchConfigurationVariable)
242
+ expect { subject.whatever }.to raise_error(A9n::NoSuchConfigurationVariableError)
243
243
  end
244
244
  end
245
245
  end
@@ -33,7 +33,7 @@ RSpec.describe A9n::Loader do
33
33
  it "raises expection" do
34
34
  expect {
35
35
  subject.load
36
- }.to raise_error(A9n::MissingConfigurationData)
36
+ }.to raise_error(A9n::MissingConfigurationDataError)
37
37
  end
38
38
  end
39
39
 
@@ -48,7 +48,7 @@ RSpec.describe A9n::Loader do
48
48
  it { expect(config.api_key).to eq("example1234") }
49
49
 
50
50
  it do
51
- expect { config.app_host }.to raise_error(A9n::NoSuchConfigurationVariable)
51
+ expect { config.app_host }.to raise_error(A9n::NoSuchConfigurationVariableError)
52
52
  end
53
53
  end
54
54
 
@@ -63,7 +63,7 @@ RSpec.describe A9n::Loader do
63
63
  it { expect(config.api_key).to eq("local1234") }
64
64
 
65
65
  it do
66
- expect { config.app_url }.to raise_error(A9n::NoSuchConfigurationVariable)
66
+ expect { config.app_url }.to raise_error(A9n::NoSuchConfigurationVariableError)
67
67
  end
68
68
  end
69
69
 
@@ -79,7 +79,7 @@ RSpec.describe A9n::Loader do
79
79
  it { expect(config.api_key).to eq("example1234") }
80
80
 
81
81
  it do
82
- expect { config.app_host }.to raise_error(A9n::NoSuchConfigurationVariable)
82
+ expect { config.app_host }.to raise_error(A9n::NoSuchConfigurationVariableError)
83
83
  end
84
84
  end
85
85
 
@@ -94,7 +94,7 @@ RSpec.describe A9n::Loader do
94
94
  it "raises expection with missing variables names" do
95
95
  expect {
96
96
  subject.load
97
- }.to raise_error(A9n::MissingConfigurationVariables, /#{missing_variables_names.join(", ")}/)
97
+ }.to raise_error(A9n::MissingConfigurationVariablesError, /#{missing_variables_names.join(", ")}/)
98
98
  end
99
99
  end
100
100
  end
@@ -124,8 +124,8 @@ RSpec.describe A9n::Loader do
124
124
  end
125
125
 
126
126
  after do
127
- ENV["ERB_DWARF"] = nil
128
- ENV["DWARF_PASSWORD"] = nil
127
+ ENV.delete("ERB_DWARF")
128
+ ENV.delete("DWARF_PASSWORD")
129
129
  end
130
130
 
131
131
  context "when file has erb extension" do
@@ -155,9 +155,18 @@ RSpec.describe A9n::Loader do
155
155
  end
156
156
 
157
157
  it "gets valus from ENV" do
158
- p subject
159
158
  expect(subject[:dwarf_password]).to eq("dwarf123")
160
159
  end
160
+
161
+ it "raises exception when ENV var is not set" do
162
+ ENV.delete("DWARF_PASSWORD")
163
+ expect{ subject[:dwarf_password] }.to raise_error(A9n::MissingEnvVariableError)
164
+ end
165
+
166
+ it "raises exception when ENV var is set to nil" do
167
+ ENV["DWARF_PASSWORD"] = nil
168
+ expect{ subject[:dwarf_password] }.to raise_error(A9n::MissingEnvVariableError)
169
+ end
161
170
  end
162
171
 
163
172
  context "having no env and only defaults data" do
@@ -33,7 +33,7 @@ RSpec.describe A9n::Struct do
33
33
  it "raises error on accessin invalid attribute" do
34
34
  expect {
35
35
  subject.dwarf
36
- }.to raise_error(A9n::NoSuchConfigurationVariable, "dwarf")
36
+ }.to raise_error(A9n::NoSuchConfigurationVariableError, "dwarf")
37
37
  end
38
38
  end
39
39
 
@@ -106,7 +106,7 @@ RSpec.describe A9n::Struct do
106
106
  it "raises exception when value not exists" do
107
107
  expect {
108
108
  subject.non_existing_dwarf
109
- }.to raise_error(A9n::NoSuchConfigurationVariable)
109
+ }.to raise_error(A9n::NoSuchConfigurationVariableError)
110
110
  end
111
111
 
112
112
  describe "#[]" do
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.6
4
+ version: 0.4.7
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-09-16 00:00:00.000000000 Z
11
+ date: 2015-10-30 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: a9n - ruby/rails apps configuration manager
14
14
  email:
@@ -61,7 +61,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
61
61
  requirements:
62
62
  - - ">="
63
63
  - !ruby/object:Gem::Version
64
- version: '0'
64
+ version: '2.0'
65
65
  required_rubygems_version: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - ">="