a9n 0.4.0 → 0.4.1

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: 5f1aa00ff577227a9d07088e0053ea48814a8816
4
- data.tar.gz: 932f917737c5c1c6cdb6919a9b16a1127a0a1c8f
3
+ metadata.gz: f02694ddef5b6bee722ffa1bc9fd625ca1ca471a
4
+ data.tar.gz: 49594a970d5088cc11229db97020b9756ae27792
5
5
  SHA512:
6
- metadata.gz: 1e69852a57a9f29d640d4983dfec8406c7943b038d07a5b58a441461a2f2ae7df8cfc6489c3df784dcb1b698a1c66ad8aeb4519c21c9bf00218217cc6478a507
7
- data.tar.gz: d578632bc24b83cbfcdc835f7a76f727ba850bd527134bdd08940823af9a49d3a6d9d9655401d3428e5fa115724bdbb8c45ec21caf11a47a3346ea014ff9acff
6
+ metadata.gz: c5795aa763517c51bb0edc2e78a8610bbc7e9c5c2c20c0031b79d0f15af1aaef4db1a6988cf4cdcb2ae899e61bc02c46f84def2ce70f11b65417b4b108adbbd4
7
+ data.tar.gz: 5f025caf0e34ef45490fa0b6d6b7daef9246cb01e658a02eecec7ac0198cf16aed33ee30e9ed4d69c736f2bdb8dd69f547f29c42f7b6f5b05a604cc515966ca8
@@ -4,7 +4,7 @@ require File.expand_path('../lib/a9n/version', __FILE__)
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ["Krzysztof Knapik"]
6
6
  gem.email = ["knapo@knapo.net"]
7
- gem.description = %q{a9n is a tool to keep ruby/rails apps extra configuration easily maintainable and verifiable}
7
+ gem.description = %q{a9n - ruby/rails apps extra configuration manager}
8
8
  gem.summary = %q{a9n is a tool to keep ruby/rails apps extra configuration easily maintainable and verifiable}
9
9
  gem.homepage = "https://github.com/knapo/a9n"
10
10
  gem.license = 'MIT'
@@ -2,21 +2,9 @@ require 'ostruct'
2
2
 
3
3
  module A9n
4
4
  class Struct < OpenStruct
5
- def empty?
6
- @table.empty?
7
- end
8
-
9
- def keys
10
- @table.keys
11
- end
5
+ extend Forwardable
12
6
 
13
- def fetch(name, default = nil)
14
- @table.fetch(name.to_sym, default)
15
- end
16
-
17
- def key?(key)
18
- to_h.key?(key)
19
- end
7
+ def_delegators :@table, :empty?, :keys, :key?
20
8
 
21
9
  def merge(key_value)
22
10
  key_value.each_pair do |key, value|
@@ -1,3 +1,3 @@
1
1
  module A9n
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -3,182 +3,226 @@ require "spec_helper"
3
3
  describe A9n do
4
4
  subject { described_class }
5
5
 
6
- after {
6
+ def clean_singleton(subject)
7
7
  subject.instance_variable_set(:@storage, nil)
8
8
  subject.instance_variable_set(:@env, nil)
9
9
  subject.root = nil
10
10
  subject.app = nil
11
- }
11
+ end
12
+
13
+ before { clean_singleton(subject) }
14
+ after { clean_singleton(subject) }
12
15
 
13
16
  describe ".env" do
14
- before {
17
+ before do
15
18
  subject.instance_variable_set(:@env, nil)
16
- }
19
+ end
17
20
 
18
21
  context "app_env is set" do
19
- before {
22
+ before do
20
23
  expect(subject).to receive(:app).and_return(double(env: "dwarf_env")).exactly(3).times
21
24
  expect(subject).to receive(:get_env_var).never
22
- }
25
+ end
23
26
 
24
- it { expect(subject.env).to eq("dwarf_env") }
27
+ it do
28
+ expect(subject.env).to eq("dwarf_env")
29
+ end
25
30
  end
26
31
 
27
32
  context "when APP_ENV is set" do
28
- before {
33
+ before do
29
34
  expect(subject).to receive(:app_env).and_return(nil)
30
35
  expect(subject).to receive(:get_env_var).with("RAILS_ENV").and_return(nil)
31
36
  expect(subject).to receive(:get_env_var).with("RACK_ENV").and_return(nil)
32
37
  expect(subject).to receive(:get_env_var).with("APP_ENV").and_return("dwarf_env")
33
- }
38
+ end
34
39
 
35
- it { expect(subject.env).to eq("dwarf_env") }
40
+ it do
41
+ expect(subject.env).to eq("dwarf_env")
42
+ end
36
43
  end
37
44
  end
38
45
 
39
46
  describe ".app" do
40
47
  context "when rails not found" do
41
- before {
48
+ before do
42
49
  expect(subject).to receive(:get_rails).and_return(nil)
43
- }
44
- specify {
50
+ end
51
+
52
+ it do
45
53
  expect(subject.app).to be_nil
46
- }
54
+ end
47
55
  end
48
56
 
49
57
  context "when rails app is being used" do
50
58
  let(:app) { double(env: "test", root: "/apps/a9n") }
51
- before {
59
+
60
+ before do
52
61
  expect(subject).to receive(:get_rails).and_return(app)
53
- }
62
+ end
54
63
 
55
- specify { expect(subject.app).to eq(app) }
64
+ it do
65
+ expect(subject.app).to eq(app)
66
+ end
56
67
  end
57
68
 
58
69
  context "when custom non-rails app is being used" do
59
70
  let(:app) { double(env: "test", root: "/apps/a9n") }
60
- before { subject.app = app }
61
71
 
62
- specify { expect(subject.app).to eq(app) }
72
+ before do
73
+ subject.app = app
74
+ end
75
+
76
+ it do
77
+ expect(subject.app).to eq(app)
78
+ end
63
79
  end
64
80
  end
65
81
 
66
82
  describe ".root" do
67
83
  let(:app) { double(env: "test", root: "/apps/a9n") }
68
- before { subject.app = app }
84
+
85
+ before do
86
+ subject.app = app
87
+ end
69
88
 
70
89
  context "with custom path" do
71
- before {
90
+ before do
72
91
  subject.root = "/home/knapo/workspace/a9n"
73
- }
74
- specify {
92
+ end
93
+
94
+ it do
75
95
  expect(subject.root).to eq(Pathname.new("/home/knapo/workspace/a9n"))
76
- }
96
+ end
77
97
  end
78
98
 
79
99
  context "with local app path" do
80
- specify {
100
+ it do
81
101
  expect(subject.root).to eq("/apps/a9n")
82
- }
102
+ end
83
103
  end
84
104
  end
85
105
 
86
106
  describe ".get_rails" do
87
107
  context "when defined" do
88
- before {
108
+ before do
89
109
  Object.const_set(:Rails, Module.new)
90
- }
91
- after {
110
+ end
111
+
112
+ after do
92
113
  Object.send(:remove_const, :Rails)
93
- }
94
- it {
114
+ end
115
+
116
+ it do
95
117
  expect(subject.get_rails).to be_kind_of(Module)
96
- }
118
+ end
97
119
  end
120
+
98
121
  context "when not defined" do
99
- it { expect(subject.get_rails).to be_nil }
122
+ it do
123
+ expect(subject.get_rails).to be_nil
124
+ end
100
125
  end
101
126
  end
102
127
 
103
128
  describe ".get_env_var" do
104
- before { ENV["DWARF"] = "little dwarf" }
105
- it { expect(subject.get_env_var("DWARF")).to eq("little dwarf")}
106
- it { expect(subject.get_env_var("IS_DWARF")).to be_nil}
129
+ before do
130
+ ENV["DWARF"] = "little dwarf"
131
+ end
132
+
133
+ it do
134
+ expect(subject.get_env_var("DWARF")).to eq("little dwarf")
135
+ end
136
+
137
+ it do
138
+ expect(subject.get_env_var("IS_DWARF")).to be_nil
139
+ end
107
140
  end
108
141
 
109
142
  describe ".default_files" do
110
- before {
143
+ before do
111
144
  subject.root = File.expand_path("../../../test_app", __FILE__)
112
- }
113
- it {
145
+ end
146
+
147
+ it do
114
148
  expect(subject.default_files[0]).to include("configuration.yml")
115
149
  expect(Pathname.new(subject.default_files[0])).to be_absolute
116
150
  expect(subject.default_files[1]).to include("a9n/mandrill.yml")
117
151
  expect(Pathname.new(subject.default_files[1])).to be_absolute
118
- }
152
+ end
119
153
  end
120
154
 
121
155
  describe ".load" do
122
- before {
156
+ before do
123
157
  expect(described_class).to receive(:env).exactly(2).times.and_return("dev")
124
158
  subject.root = "/apps/test_app"
125
159
  files.each do |f, cfg|
126
160
  expect(A9n::Loader).to receive(:new).with(f, "dev").and_return(double(get: cfg))
127
161
  end
128
- }
162
+ end
163
+
129
164
  context "when no files given" do
130
- let(:files) {
165
+ let(:files) do
131
166
  {
132
167
  "/apps/test_app/config/file1.yml" => { host: "host1.com" },
133
168
  "/apps/test_app/config/dir/file2.yml" => { host: "host2.com" }
134
169
  }
135
- }
136
- before {
170
+ end
171
+
172
+ before do
137
173
  expect(subject).to receive(:default_files).and_return(files.keys)
138
174
  expect(subject).to receive(:get_absolute_paths_for).never
139
- }
140
- it {
175
+ end
176
+
177
+ it do
141
178
  expect(subject.load).to eq(files.values)
142
- }
179
+ end
143
180
  end
144
181
 
145
182
  context "when custom files given" do
146
- let(:given_files) {
183
+ let(:given_files) do
147
184
  ["file3.yml", "/apps/test_app/config/dir/file4.yml"]
148
- }
149
- let(:files) {
185
+ end
186
+
187
+ let(:files) do
150
188
  {
151
189
  "/apps/test_app/config/file3.yml" => { host: "host3.com" },
152
190
  "/apps/test_app/config/dir/file4.yml" => { host: "host4.com" }
153
191
  }
154
- }
155
- before {
192
+ end
193
+
194
+ before do
156
195
  expect(subject).to receive(:default_files).never
157
196
  expect(subject).to receive(:get_absolute_paths_for).with(given_files).and_call_original
158
- }
159
- it {
197
+ end
198
+
199
+ it do
160
200
  expect(subject.load(*given_files)).to eq(files.values)
161
- }
201
+ end
162
202
  end
163
203
  end
164
204
 
165
205
  describe ".method_missing" do
166
206
  context "when storage is empty" do
167
- before { expect(subject).to receive(:load).once }
168
- it {
207
+ before do
208
+ expect(subject).to receive(:load).once
209
+ end
210
+
211
+ it do
169
212
  expect(subject.storage).to be_empty
170
213
  expect { subject.whatever }.to raise_error(A9n::NoSuchConfigurationVariable)
171
- }
214
+ end
172
215
  end
173
216
 
174
217
  context "when storage is not empty" do
175
- before {
218
+ before do
176
219
  subject.storage[:whenever] = 'whenever'
177
220
  expect(subject).not_to receive(:load)
178
- }
179
- it {
221
+ end
222
+
223
+ it do
180
224
  expect { subject.whatever }.to raise_error(A9n::NoSuchConfigurationVariable)
181
- }
225
+ end
182
226
  end
183
227
  end
184
228
  end
@@ -30,6 +30,7 @@ describe A9n::Loader do
30
30
  expect(described_class).to receive(:load_yml).with(subject.local_file, env).and_return(nil)
31
31
  expect(subject).to receive(:verify!).never
32
32
  end
33
+
33
34
  it "raises expection" do
34
35
  expect {
35
36
  subject.load
@@ -48,9 +49,9 @@ describe A9n::Loader do
48
49
  it { expect(config.app_url).to eq("http://127.0.0.1:3000") }
49
50
  it { expect(config.api_key).to eq("example1234") }
50
51
 
51
- it {
52
+ it do
52
53
  expect { config.app_host }.to raise_error(A9n::NoSuchConfigurationVariable)
53
- }
54
+ end
54
55
  end
55
56
 
56
57
  context "when only local configuration file exists" do
@@ -60,12 +61,13 @@ describe A9n::Loader do
60
61
  expect(described_class).to receive(:verify!).never
61
62
  subject.load
62
63
  end
64
+
63
65
  it { expect(config.app_host).to eq("127.0.0.1:3000") }
64
66
  it { expect(config.api_key).to eq("local1234") }
65
67
 
66
- it {
68
+ it do
67
69
  expect { config.app_url }.to raise_error(A9n::NoSuchConfigurationVariable)
68
- }
70
+ end
69
71
  end
70
72
 
71
73
  context "when both local and base configuration file exists without defaults" do
@@ -79,9 +81,9 @@ describe A9n::Loader do
79
81
  it { expect(config.app_url).to eq("http://127.0.0.1:3000") }
80
82
  it { expect(config.api_key).to eq("example1234") }
81
83
 
82
- it {
84
+ it do
83
85
  expect { config.app_host }.to raise_error(A9n::NoSuchConfigurationVariable)
84
- }
86
+ end
85
87
  end
86
88
 
87
89
  context "with different data" do
@@ -95,7 +97,7 @@ describe A9n::Loader do
95
97
  it "raises expection with missing variables names" do
96
98
  expect {
97
99
  subject.load
98
- }.to raise_error(A9n::MissingConfigurationVariables, /#{missing_variables_names.join(', ')}/)
100
+ }.to raise_error(A9n::MissingConfigurationVariables, /#{missing_variables_names.join(", ")}/)
99
101
  end
100
102
  end
101
103
  end
@@ -119,11 +121,11 @@ describe A9n::Loader do
119
121
  end
120
122
  end
121
123
 
122
- before {
124
+ before do
123
125
  ENV["DWARF"] = "erbized dwarf"
124
- }
126
+ end
125
127
 
126
- context 'when file has erb extension' do
128
+ context "when file has erb extension" do
127
129
  let(:file_path) { File.join(root, "config/a9n/cloud.yml.erb") }
128
130
 
129
131
  it_behaves_like "non-empty config file"
@@ -1,108 +1,119 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
3
  describe A9n::Struct do
4
4
  context "without any values" do
5
5
  subject { described_class.new }
6
6
 
7
- it 'is empty' do
8
- expect(subject).to be_empty
7
+ describe "#empty?" do
8
+ it { expect(subject).to be_empty }
9
9
  end
10
10
 
11
- it 'raises error' do
11
+ describe "#keys" do
12
+ it { expect(subject.keys).to eq([]) }
13
+ end
14
+
15
+ describe "#key?" do
16
+ it { expect(subject.key?(:dwarf)).to eq(false) }
17
+ end
18
+
19
+ describe "#[]" do
20
+ it { expect(subject[:dwarf]).to be_nil }
21
+ end
22
+
23
+ it "raises error on accessin invalid attribute" do
12
24
  expect {
13
25
  subject.dwarf
14
- }.to raise_error(A9n::NoSuchConfigurationVariable, 'dwarf')
26
+ }.to raise_error(A9n::NoSuchConfigurationVariable, "dwarf")
15
27
  end
16
28
  end
17
29
 
18
30
  context "with values" do
19
31
  subject {
20
32
  described_class.new({
21
- non_empty_dwarf: 'dwarf',
33
+ non_empty_dwarf: "dwarf",
22
34
  nil_dwarf: nil,
23
35
  false_dwarf: false,
24
36
  true_dwarf: true,
25
- hash_dwarf: { dwarf: 'hello' }
37
+ hash_dwarf: { dwarf: "hello" }
26
38
  })
27
39
  }
28
40
 
29
- describe '#keys' do
30
- subject { super().keys }
31
-
41
+ describe "#keys" do
32
42
  it do
33
- expect(subject).to eq [:non_empty_dwarf, :nil_dwarf, :false_dwarf, :true_dwarf, :hash_dwarf]
43
+ expect(subject.keys).to eq [:non_empty_dwarf, :nil_dwarf, :false_dwarf, :true_dwarf, :hash_dwarf]
34
44
  end
35
45
  end
36
46
 
37
- describe '#merge' do
47
+ describe "#key?" do
48
+ it { expect(subject.key?(:nil_dwarf)).to eq(true) }
49
+ it { expect(subject.key?(:unknown)).to eq(false) }
50
+ end
51
+
52
+ describe "#merge" do
38
53
  before { subject.merge(argument) }
39
54
 
40
- context 'hash' do
41
- let(:argument) { { non_empty_dwarf: 'hello dwarf' } }
55
+ context "hash" do
56
+ let(:argument) { { non_empty_dwarf: "hello dwarf" } }
42
57
 
43
58
  it do
44
- expect(subject.non_empty_dwarf).to eq('hello dwarf')
59
+ expect(subject.non_empty_dwarf).to eq("hello dwarf")
45
60
  end
46
61
  end
47
62
 
48
- context 'struct' do
49
- let(:argument) { described_class.new(non_empty_dwarf: 'hello dwarf') }
63
+ context "struct" do
64
+ let(:argument) { described_class.new(non_empty_dwarf: "hello dwarf") }
50
65
 
51
66
  it do
52
- expect(subject.non_empty_dwarf).to eq('hello dwarf')
67
+ expect(subject.non_empty_dwarf).to eq("hello dwarf")
53
68
  end
54
69
  end
55
70
  end
56
71
 
57
- it 'is not empty' do
72
+ it "is not empty" do
58
73
  expect(subject).not_to be_empty
59
74
  end
60
75
 
61
- it 'gets non-empty value' do
62
- expect(subject.non_empty_dwarf).to eq('dwarf')
76
+ it "gets non-empty value" do
77
+ expect(subject.non_empty_dwarf).to eq("dwarf")
63
78
  end
64
79
 
65
- it 'gets nil value' do
80
+ it "gets nil value" do
66
81
  expect(subject.nil_dwarf).to eq(nil)
67
82
  end
68
83
 
69
- it 'gets true value' do
84
+ it "gets true value" do
70
85
  expect(subject.true_dwarf).to eq(true)
71
86
  end
72
87
 
73
- it 'gets false value' do
88
+ it "gets false value" do
74
89
  expect(subject.false_dwarf).to eq(false)
75
90
  end
76
91
 
77
- it 'gets hash value' do
92
+ it "gets hash value" do
78
93
  expect(subject.hash_dwarf).to be_kind_of(Hash)
79
94
  end
80
95
 
81
- it 'raises exception when value not exists' do
96
+ it "raises exception when value not exists" do
82
97
  expect {
83
98
  subject.non_existing_dwarf
84
99
  }.to raise_error(A9n::NoSuchConfigurationVariable)
85
100
  end
86
101
 
87
- describe '#fetch' do
88
- it 'return non empty value' do
89
- expect(subject.fetch(:non_empty_dwarf)).to eq('dwarf')
90
- end
91
-
92
- it 'return false value' do
93
- expect(subject.fetch(:false_dwarf)).to eq(false)
102
+ describe "#[]" do
103
+ it "return non empty value" do
104
+ expect(subject[:non_empty_dwarf]).to eq("dwarf")
94
105
  end
95
106
 
96
- it 'return nil value' do
97
- expect(subject.fetch(:nil_dwarf)).to eq(nil)
107
+ it "return false value" do
108
+ expect(subject[:false_dwarf]).to eq(false)
98
109
  end
99
110
 
100
- it 'return nil for non existing value' do
101
- expect(subject.fetch(:non_existing_dwarf)).to eq(nil)
111
+ it "return nil value" do
112
+ expect(subject[:nil_dwarf]).to eq(nil)
102
113
  end
103
114
 
104
- it 'return default for non existing value' do
105
- expect(subject.fetch(:non_existing_dwarf, 'default')).to eq('default')
115
+ it "return nil for non existing value" do
116
+ expect(subject[:non_existing_dwarf]).to eq(nil)
106
117
  end
107
118
  end
108
119
  end
metadata CHANGED
@@ -1,17 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: a9n
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
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-17 00:00:00.000000000 Z
11
+ date: 2015-02-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: a9n is a tool to keep ruby/rails apps extra configuration easily maintainable
14
- and verifiable
13
+ description: a9n - ruby/rails apps extra configuration manager
15
14
  email:
16
15
  - knapo@knapo.net
17
16
  executables: []