a9n 0.4.1 → 0.4.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: f02694ddef5b6bee722ffa1bc9fd625ca1ca471a
4
- data.tar.gz: 49594a970d5088cc11229db97020b9756ae27792
3
+ metadata.gz: cb78fbff3f0313e316677658597f0143d5688835
4
+ data.tar.gz: ec4ee59ac801e019236d895674b325ac0b720483
5
5
  SHA512:
6
- metadata.gz: c5795aa763517c51bb0edc2e78a8610bbc7e9c5c2c20c0031b79d0f15af1aaef4db1a6988cf4cdcb2ae899e61bc02c46f84def2ce70f11b65417b4b108adbbd4
7
- data.tar.gz: 5f025caf0e34ef45490fa0b6d6b7daef9246cb01e658a02eecec7ac0198cf16aed33ee30e9ed4d69c736f2bdb8dd69f547f29c42f7b6f5b05a604cc515966ca8
6
+ metadata.gz: 6325f3fbad2cc18a3d8eb78cde05aebf3c3a0ea62f7a0c1b4e4c2b27e2901919f292c8d268a90319baf053235fcc0055e46aea595a1be764c896b0339fcd88dd
7
+ data.tar.gz: d0d1228d3b001208f1296f2f6e9468173acac35169cf34810dce9fd303c811ffd303fb9027db19a51d411c3207ba0d8108c90818654f7323daa3bd2a9d07361f
data/Gemfile CHANGED
@@ -2,5 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
4
4
  gem 'rake'
5
- gem 'rspec', '~> 3.0.0'
5
+ gem 'rspec'
6
6
  gem 'codeclimate-test-reporter', require: false
@@ -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 - ruby/rails apps extra configuration manager}
7
+ gem.description = %q{a9n - ruby/rails apps 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'
data/lib/a9n.rb CHANGED
@@ -66,7 +66,7 @@ module A9n
66
66
 
67
67
  def method_missing(name, *args)
68
68
  load if storage.empty?
69
- storage.send(name)
69
+ storage.send(name, *args)
70
70
  end
71
71
 
72
72
  private
@@ -80,10 +80,11 @@ module A9n
80
80
  def setup_scope(name, data)
81
81
  if default_scope?(name)
82
82
  storage.merge(data)
83
+ def_delegator :storage, :fetch
83
84
  def_delegators :storage, *data.keys
84
85
  else
85
86
  storage[name] = data
86
- def_delegators :storage, name
87
+ def_delegator :storage, name
87
88
  end
88
89
  return data
89
90
  end
@@ -4,7 +4,7 @@ module A9n
4
4
  class Struct < OpenStruct
5
5
  extend Forwardable
6
6
 
7
- def_delegators :@table, :empty?, :keys, :key?
7
+ def_delegators :@table, :empty?, :keys, :key?, :fetch
8
8
 
9
9
  def merge(key_value)
10
10
  key_value.each_pair do |key, value|
@@ -1,3 +1,3 @@
1
1
  module A9n
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
@@ -5,53 +5,114 @@ describe A9n do
5
5
 
6
6
  let(:env) { "test" }
7
7
 
8
- before {
8
+ before do
9
+ clean_singleton(subject)
9
10
  subject.app = double(env: env)
10
11
  subject.root = File.expand_path("../../../test_app", __FILE__)
11
12
  subject.load
12
- }
13
+ end
13
14
 
14
- after {
15
- subject.instance_variable_set(:@env, nil)
16
- subject.root = nil
17
- subject.app = nil
18
- }
15
+ after do
16
+ clean_singleton(subject)
17
+ end
19
18
 
20
19
  context "base config file" do
21
- it {
20
+ it do
21
+ expect(subject.storage).to be_kind_of(A9n::Struct)
22
+ end
23
+
24
+ it do
22
25
  expect(subject.default_dwarf).to eq("default dwarf")
23
26
  expect(subject.overriden_dwarf).to eq("already overriden dwarf")
24
- }
27
+ end
28
+
29
+ it do
30
+ expect(subject.fetch(:default_dwarf)).to eq("default dwarf")
31
+ expect(subject.fetch(:overriden_dwarf)).to eq("already overriden dwarf")
32
+ end
33
+
34
+ it do
35
+ expect { subject.invalid }.to raise_error(A9n::NoSuchConfigurationVariable)
36
+ end
37
+
38
+ it do
39
+ expect { subject.fetch(:invalid) }.to raise_error(::KeyError)
40
+ end
41
+
42
+ it do
43
+ expect { subject.fetch(:invalid, "Hello").to eq("Hello") }
44
+ end
25
45
  end
26
46
 
27
47
  context "undefined env" do
28
48
  let(:env) { "tropical" }
29
- it {
49
+
50
+ it do
30
51
  expect(subject.default_dwarf).to eq("default dwarf")
31
52
  expect(subject.overriden_dwarf).to eq("not yet overriden dwarf")
32
- }
53
+ end
54
+
55
+ it do
56
+ expect(subject.fetch(:default_dwarf)).to eq("default dwarf")
57
+ expect(subject.fetch(:overriden_dwarf)).to eq("not yet overriden dwarf")
58
+ end
33
59
  end
34
60
 
35
61
  context "extra config file" do
36
- it {
62
+ before do
37
63
  expect(subject.mandrill).to be_kind_of(A9n::Struct)
64
+ end
65
+
66
+ it do
38
67
  expect(subject.mandrill.username).to eq("joe")
39
68
  expect(subject.mandrill.api_key).to eq("asdf1234")
40
- }
69
+ end
70
+
71
+ it do
72
+ expect(subject.mandrill.fetch(:username)).to eq("joe")
73
+ expect(subject.mandrill.fetch(:api_key)).to eq("asdf1234")
74
+ end
75
+
76
+ it do
77
+ expect(subject.fetch(:mandrill)).to eq(subject.mandrill)
78
+ end
41
79
  end
42
80
 
43
81
  context "extra config file with erb" do
44
- it {
82
+ before do
45
83
  expect(subject.cloud).to be_kind_of(A9n::Struct)
84
+ end
85
+
86
+ it do
46
87
  expect(subject.cloud.username).to eq("testuser")
47
88
  expect(subject.cloud.password).to eq("qwerty")
48
- }
89
+ end
90
+
91
+ it do
92
+ expect(subject.cloud.fetch(:username)).to eq("testuser")
93
+ expect(subject.cloud.fetch(:password)).to eq("qwerty")
94
+ end
95
+
96
+ it do
97
+ expect(subject.fetch(:cloud)).to eq(subject.cloud)
98
+ end
49
99
  end
50
100
 
51
101
  context "extra config file with example" do
52
- it {
102
+ before do
53
103
  expect(subject.mailer).to be_kind_of(A9n::Struct)
104
+ end
105
+
106
+ it do
54
107
  expect(subject.mailer.delivery_method).to eq("test")
55
- }
108
+ end
109
+
110
+ it do
111
+ expect(subject.mailer.fetch(:delivery_method)).to eq("test")
112
+ end
113
+
114
+ it do
115
+ expect(subject.fetch(:mailer)).to eq(subject.mailer)
116
+ end
56
117
  end
57
118
  end
@@ -15,3 +15,11 @@ RSpec.configure do |config|
15
15
  config.order = "random"
16
16
  config.tty = true
17
17
  end
18
+
19
+ def clean_singleton(klass)
20
+ [:@storage, :@env, :@app, :@root].each do |var|
21
+ if klass.instance_variable_defined?(var)
22
+ klass.remove_instance_variable(var)
23
+ end
24
+ end
25
+ end
@@ -2,14 +2,6 @@ require "spec_helper"
2
2
 
3
3
  describe A9n do
4
4
  subject { described_class }
5
-
6
- def clean_singleton(subject)
7
- subject.instance_variable_set(:@storage, nil)
8
- subject.instance_variable_set(:@env, nil)
9
- subject.root = nil
10
- subject.app = nil
11
- end
12
-
13
5
  before { clean_singleton(subject) }
14
6
  after { clean_singleton(subject) }
15
7
 
@@ -17,7 +17,19 @@ describe A9n::Struct do
17
17
  end
18
18
 
19
19
  describe "#[]" do
20
- it { expect(subject[:dwarf]).to be_nil }
20
+ it { expect(subject[:dwarf]).to eq(nil) }
21
+ end
22
+
23
+ describe "#fetch" do
24
+ it do
25
+ expect {
26
+ subject.fetch(:dwarf)
27
+ }.to raise_error(KeyError)
28
+ end
29
+
30
+ it do
31
+ expect(subject.fetch(:dwarf, "hello")).to eq("hello")
32
+ end
21
33
  end
22
34
 
23
35
  it "raises error on accessin invalid attribute" do
@@ -100,21 +112,46 @@ describe A9n::Struct do
100
112
  end
101
113
 
102
114
  describe "#[]" do
103
- it "return non empty value" do
115
+ it "returns non empty value" do
104
116
  expect(subject[:non_empty_dwarf]).to eq("dwarf")
105
117
  end
106
118
 
107
- it "return false value" do
119
+ it "returns false value" do
108
120
  expect(subject[:false_dwarf]).to eq(false)
109
121
  end
110
122
 
111
- it "return nil value" do
123
+ it "returns nil value" do
112
124
  expect(subject[:nil_dwarf]).to eq(nil)
113
125
  end
114
126
 
115
- it "return nil for non existing value" do
127
+ it "returns nil for non existing key" do
116
128
  expect(subject[:non_existing_dwarf]).to eq(nil)
117
129
  end
118
130
  end
131
+
132
+
133
+ describe "#fetch" do
134
+ it "returns non empty value" do
135
+ expect(subject.fetch(:non_empty_dwarf)).to eq("dwarf")
136
+ end
137
+
138
+ it "returns false value" do
139
+ expect(subject.fetch(:false_dwarf)).to eq(false)
140
+ end
141
+
142
+ it "returns nil value" do
143
+ expect(subject.fetch(:nil_dwarf)).to eq(nil)
144
+ end
145
+
146
+ it "returns default for non existing value" do
147
+ expect(subject.fetch(:non_existing_dwarf, "hello")).to eq("hello")
148
+ end
149
+
150
+ it "raises error for non existing key" do
151
+ expect {
152
+ subject.fetch(:non_existing_dwarf)
153
+ }.to raise_error(KeyError)
154
+ end
155
+ end
119
156
  end
120
157
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: a9n
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.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: 2015-02-18 00:00:00.000000000 Z
11
+ date: 2015-02-24 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: a9n - ruby/rails apps extra configuration manager
13
+ description: a9n - ruby/rails apps configuration manager
14
14
  email:
15
15
  - knapo@knapo.net
16
16
  executables: []