a9n 0.10.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,27 +0,0 @@
1
- RSpec.describe A9n::Scope do
2
- subject { described_class.new(name) }
3
-
4
- describe '#name' do
5
- let(:name) { 'configuration' }
6
- it { expect(subject.name).to eq(:configuration) }
7
- end
8
-
9
- describe '#main?' do
10
- context 'when name is configuration' do
11
- let(:name) { 'configuration' }
12
- it { expect(subject).to be_root }
13
- end
14
-
15
- context 'when name is other than configuration' do
16
- let(:name) { 'google' }
17
- it { expect(subject).not_to be_root }
18
- end
19
- end
20
-
21
- describe '.form_file_path' do
22
- let(:path) { 'config/a9n/google.yml.example' }
23
- subject { described_class.form_file_path(path) }
24
-
25
- it { expect(subject.name).to eq(:google) }
26
- end
27
- end
@@ -1,168 +0,0 @@
1
- RSpec.describe A9n::Struct do
2
- context 'without any values' do
3
- subject { described_class.new }
4
-
5
- describe '#empty?' do
6
- it { expect(subject).to be_empty }
7
- end
8
-
9
- describe '#keys' do
10
- it { expect(subject.keys).to eq([]) }
11
- end
12
-
13
- describe '#key?' do
14
- it { expect(subject.key?(:foo)).to eq(false) }
15
- end
16
-
17
- describe '#[]' do
18
- it { expect(subject[:foo]).to eq(nil) }
19
- end
20
-
21
- describe '#fetch' do
22
- it do
23
- expect { subject.fetch(:foo) }.to raise_error(KeyError)
24
- end
25
-
26
- it do
27
- expect(subject.fetch(:foo, 'hello')).to eq('hello')
28
- end
29
- end
30
-
31
- it 'raises error on accessin invalid attribute' do
32
- expect {
33
- subject.foo
34
- }.to raise_error(A9n::NoSuchConfigurationVariableError, 'foo')
35
- end
36
- end
37
-
38
- context 'with values' do
39
- let(:data) do
40
- {
41
- non_empty_foo: 'foo',
42
- nil_foo: nil,
43
- false_foo: false,
44
- true_foo: true,
45
- hash_foo: { foo: 'hello' }
46
- }
47
- end
48
-
49
- subject { described_class.new(data) }
50
-
51
- describe '#keys' do
52
- it do
53
- expect(subject.keys).to eq [:non_empty_foo, :nil_foo, :false_foo, :true_foo, :hash_foo]
54
- end
55
- end
56
-
57
- describe '#to_h' do
58
- it do
59
- expect(subject.to_h).to be_kind_of(Hash)
60
- expect(subject.to_h).to eq(data)
61
- end
62
- end
63
-
64
- describe '#to_hash' do
65
- it do
66
- expect(subject.to_hash).to be_kind_of(Hash)
67
- expect(subject.to_hash).to eq(data)
68
- end
69
- end
70
-
71
- describe '#key?' do
72
- it { expect(subject.key?(:nil_foo)).to eq(true) }
73
- it { expect(subject.key?(:unknown)).to eq(false) }
74
- end
75
-
76
- describe '#merge' do
77
- before { subject.merge(argument) }
78
-
79
- context 'hash' do
80
- let(:argument) { { non_empty_foo: 'hello foo' } }
81
-
82
- it do
83
- expect(subject.non_empty_foo).to eq('hello foo')
84
- end
85
- end
86
-
87
- context 'struct' do
88
- let(:argument) { described_class.new(non_empty_foo: 'hello foo') }
89
-
90
- it do
91
- expect(subject.non_empty_foo).to eq('hello foo')
92
- end
93
- end
94
- end
95
-
96
- it 'is not empty' do
97
- expect(subject).not_to be_empty
98
- end
99
-
100
- it 'gets non-empty value' do
101
- expect(subject.non_empty_foo).to eq('foo')
102
- end
103
-
104
- it 'gets nil value' do
105
- expect(subject.nil_foo).to eq(nil)
106
- end
107
-
108
- it 'gets true value' do
109
- expect(subject.true_foo).to eq(true)
110
- end
111
-
112
- it 'gets false value' do
113
- expect(subject.false_foo).to eq(false)
114
- end
115
-
116
- it 'gets hash value' do
117
- expect(subject.hash_foo).to be_kind_of(Hash)
118
- end
119
-
120
- it 'raises exception when value not exists' do
121
- expect {
122
- subject.non_existing_foo
123
- }.to raise_error(A9n::NoSuchConfigurationVariableError)
124
- end
125
-
126
- describe '#[]' do
127
- it 'returns non empty value' do
128
- expect(subject[:non_empty_foo]).to eq('foo')
129
- end
130
-
131
- it 'returns false value' do
132
- expect(subject[:false_foo]).to eq(false)
133
- end
134
-
135
- it 'returns nil value' do
136
- expect(subject[:nil_foo]).to eq(nil)
137
- end
138
-
139
- it 'returns nil for non existing key' do
140
- expect(subject[:non_existing_foo]).to eq(nil)
141
- end
142
- end
143
-
144
- describe '#fetch' do
145
- it 'returns non empty value' do
146
- expect(subject.fetch(:non_empty_foo)).to eq('foo')
147
- end
148
-
149
- it 'returns false value' do
150
- expect(subject.fetch(:false_foo)).to eq(false)
151
- end
152
-
153
- it 'returns nil value' do
154
- expect(subject.fetch(:nil_foo)).to eq(nil)
155
- end
156
-
157
- it 'returns default for non existing value' do
158
- expect(subject.fetch(:non_existing_foo, 'hello')).to eq('hello')
159
- end
160
-
161
- it 'raises error for non existing key' do
162
- expect {
163
- subject.fetch(:non_existing_foo)
164
- }.to raise_error(KeyError)
165
- end
166
- end
167
- end
168
- end
@@ -1,31 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler/setup'
3
- require 'benchmark'
4
- require 'a9n'
5
-
6
- class SampleBenchmarkApp
7
- def run
8
- 0.upto(1_000).map do |index|
9
- "#{index} #{::A9n.string_foo} #{::A9n.overriden_foo}"
10
- end
11
- end
12
-
13
- def root
14
- Pathname.new('./test_app').expand_path
15
- end
16
-
17
- def env
18
- :test
19
- end
20
- end
21
-
22
- A9n.app = SampleBenchmarkApp.new
23
- results = []
24
-
25
- 10.times do
26
- results << Benchmark.realtime { A9n.app.run }
27
- end
28
-
29
- human_result = (results.reduce(&:+) / 10).round(4)
30
-
31
- puts human_result
@@ -1,25 +0,0 @@
1
- defaults:
2
- default_foo: "default foo"
3
- overriden_foo: "not yet overriden foo"
4
- erb_foo: "<%= ENV['ERB_FOO'] %>"
5
- foo_password: :env
6
- development:
7
- nil_foo: ~
8
- false_foo: false
9
- true_foo: true
10
- string_foo: "foo"
11
- overriden_foo: "already overriden foo"
12
- hash_foo:
13
- foo_1: "hello 1"
14
- foo_2: "hello 2"
15
- foo_key: :env
16
- test:
17
- nil_foo: ~
18
- false_foo: false
19
- true_foo: true
20
- string_foo: "foo"
21
- overriden_foo: "already overriden foo"
22
- hash_foo:
23
- foo_1: "hello 1"
24
- foo_2: "hello 2"
25
- foo_key: :env
@@ -1,23 +0,0 @@
1
- defaults:
2
- default_foo: "example default foo"
3
- overriden_foo: "example not yet overriden foo"
4
- erb_foo: "<%= ENV['ERB_FOO'] %>"
5
- foo_password: :env
6
- development:
7
- nil_foo: ~
8
- false_foo: false
9
- true_foo: true
10
- string_foo: "foo"
11
- overriden_foo: "example already overriden foo"
12
- hash_foo:
13
- foo_1: "hello 1"
14
- foo_2: "hello 2"
15
- test:
16
- nil_foo: ~
17
- false_foo: false
18
- true_foo: true
19
- string_foo: "foo"
20
- overriden_foo: "example already overriden foo"
21
- hash_foo:
22
- foo_1: "hello 1"
23
- foo_2: "hello 2"
@@ -1,3 +0,0 @@
1
- defaults:
2
- username: "joe"
3
- api_key: :env
@@ -1,3 +0,0 @@
1
- defaults:
2
- username: "testuser"
3
- password: "qwerty"
@@ -1,2 +0,0 @@
1
- knapo: "knapo@a9n.local"
2
- admin: "admin@a9n.local"
@@ -1,2 +0,0 @@
1
- defaults:
2
- delivery_method: test
@@ -1,3 +0,0 @@
1
- production:
2
- username: "joe"
3
- api_key: "asdf1234"