gem_config 0.2.4 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +2 -2
- data/README.md +6 -0
- data/gem_config.gemspec +1 -1
- data/lib/gem_config.rb +3 -0
- data/lib/gem_config/configuration.rb +5 -4
- data/lib/gem_config/rules.rb +0 -2
- data/lib/gem_config/version.rb +1 -1
- data/spec/lib/configuration_spec.rb +25 -2
- data/spec/lib/rules_spec.rb +5 -5
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1046dd50da7f348b21c6bfcc3e71903012f82897
|
4
|
+
data.tar.gz: 44245b10f3f50bd9edde6414fb25f109bbd5378c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 01e105eeb51018f58561cecaeb4816ba754449488401d58c1544bdbfa145124a4689231014c40fefd66e988b600dd35094cc634bb1c8009d8993801f0ea6c202
|
7
|
+
data.tar.gz: 6402a8a2746c3319e2742db56c4f8999a032f18242f9f4b7187583471c8ec641f798e42d4f524926257c43955c6ad68132f9e4e6a7227420672832ab8220e832
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -19,8 +19,12 @@ Gem::Specification.new do |gem|
|
|
19
19
|
...
|
20
20
|
gem.add_runtime_dependency 'gem_config'
|
21
21
|
end
|
22
|
+
```
|
22
23
|
|
24
|
+
```ruby
|
23
25
|
# lib/awesomeness.rb
|
26
|
+
require 'gem_config'
|
27
|
+
|
24
28
|
module Awesomeness
|
25
29
|
include GemConfig::Base
|
26
30
|
|
@@ -45,7 +49,9 @@ Include and configure a gem like this:
|
|
45
49
|
```ruby
|
46
50
|
# Gemfile
|
47
51
|
gem 'awesomeness'
|
52
|
+
```
|
48
53
|
|
54
|
+
```ruby
|
49
55
|
# config/initializers/awesomeness.rb
|
50
56
|
Awesomeness.configure do |config|
|
51
57
|
config.api_key = 'foobarbaz'
|
data/gem_config.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |gem|
|
|
8
8
|
gem.version = GemConfig::VERSION
|
9
9
|
gem.platform = Gem::Platform::RUBY
|
10
10
|
gem.authors = ['Manuel Meurer']
|
11
|
-
gem.email = 'manuel
|
11
|
+
gem.email = 'manuel@krautcomputing.com'
|
12
12
|
gem.summary = 'A nifty way to make your gem configurable.'
|
13
13
|
gem.description = 'A nifty way to make your gem configurable.'
|
14
14
|
gem.homepage = 'https://github.com/krautcomputing/gem_config'
|
data/lib/gem_config.rb
CHANGED
@@ -16,6 +16,11 @@ module GemConfig
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
+
def unset(key)
|
20
|
+
raise InvalidKeyError, "#{key} is not a valid key." unless self.rules.keys.include?(key.to_sym)
|
21
|
+
remove_instance_variable "@#{key}" if instance_variable_defined?("@#{key}")
|
22
|
+
end
|
23
|
+
|
19
24
|
def method_missing(method, *args, &block)
|
20
25
|
case
|
21
26
|
when self.rules.keys.include?(method.to_sym)
|
@@ -29,10 +34,6 @@ module GemConfig
|
|
29
34
|
|
30
35
|
private
|
31
36
|
|
32
|
-
def unset(key)
|
33
|
-
remove_instance_variable "@#{key}" if instance_variable_defined?("@#{key}")
|
34
|
-
end
|
35
|
-
|
36
37
|
def set(key, value)
|
37
38
|
self.rules.check(key, value)
|
38
39
|
instance_variable_set "@#{key}", value
|
data/lib/gem_config/rules.rb
CHANGED
data/lib/gem_config/version.rb
CHANGED
@@ -4,6 +4,7 @@ describe GemConfig::Configuration do
|
|
4
4
|
subject do
|
5
5
|
GemConfig::Configuration.new.tap do |configuration|
|
6
6
|
configuration.rules.has :foo, default: 'bar'
|
7
|
+
configuration.rules.has :bar
|
7
8
|
configuration.rules.has :count
|
8
9
|
configuration.rules.has :api_key, default: 'foobarbaz'
|
9
10
|
configuration.foo = 'pelle'
|
@@ -30,6 +31,28 @@ describe GemConfig::Configuration do
|
|
30
31
|
end
|
31
32
|
end
|
32
33
|
|
34
|
+
describe '#unset' do
|
35
|
+
context 'with an existing key' do
|
36
|
+
context 'when that key has not been set' do
|
37
|
+
it 'doesnt change anything' do
|
38
|
+
expect { subject.unset(:bar) }.to_not change { subject.bar }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context 'when that key has been set' do
|
43
|
+
it 'unsets the key' do
|
44
|
+
expect { subject.unset(:count) }.to change { subject.count }.from(123).to(nil)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'with a non-existing key' do
|
50
|
+
it 'raises an exception' do
|
51
|
+
expect { subject.unset(:pelle) }.to raise_error(GemConfig::InvalidKeyError)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
33
56
|
describe 'setting a configuration option' do
|
34
57
|
it 'checks if the value is allowed' do
|
35
58
|
subject.rules.should_receive :check, with: [:foo, 'bar']
|
@@ -44,11 +67,11 @@ describe GemConfig::Configuration do
|
|
44
67
|
end
|
45
68
|
|
46
69
|
it 'does not set the configuration option if the value is not allowed' do
|
47
|
-
subject.rules.stub(:check, with: [:foo, 'bar']).and_raise(GemConfig::
|
70
|
+
subject.rules.stub(:check, with: [:foo, 'bar']).and_raise(GemConfig::InvalidKeyError)
|
48
71
|
expect do
|
49
72
|
begin
|
50
73
|
subject.foo = 'bar'
|
51
|
-
rescue GemConfig::
|
74
|
+
rescue GemConfig::InvalidKeyError
|
52
75
|
end
|
53
76
|
end.to_not change { subject.foo }.from('bar')
|
54
77
|
end
|
data/spec/lib/rules_spec.rb
CHANGED
@@ -122,35 +122,35 @@ describe GemConfig::Rules do
|
|
122
122
|
it "raises an error if the value is not set as a rule" do
|
123
123
|
expect do
|
124
124
|
subject.check :foo, 1
|
125
|
-
end.to raise_error(GemConfig::
|
125
|
+
end.to raise_error(GemConfig::InvalidKeyError)
|
126
126
|
end
|
127
127
|
|
128
128
|
it "raises an error if :classes are defined the the value's class is not included in them" do
|
129
129
|
subject.has :foo, classes: String
|
130
130
|
expect do
|
131
131
|
subject.check :foo, 1
|
132
|
-
end.to raise_error(GemConfig::
|
132
|
+
end.to raise_error(GemConfig::InvalidKeyError)
|
133
133
|
end
|
134
134
|
|
135
135
|
it 'raises an error if :values are defined the the value is not included in them' do
|
136
136
|
subject.has :foo, values: ['foo', 'bar']
|
137
137
|
expect do
|
138
138
|
subject.check :foo, 'baz'
|
139
|
-
end.to raise_error(GemConfig::
|
139
|
+
end.to raise_error(GemConfig::InvalidKeyError)
|
140
140
|
end
|
141
141
|
|
142
142
|
it "does not raise an error if :classes are defined the the value's class is included in them" do
|
143
143
|
subject.has :foo, classes: [String, Numeric]
|
144
144
|
expect do
|
145
145
|
subject.check :foo, 1
|
146
|
-
end.to_not raise_error(GemConfig::
|
146
|
+
end.to_not raise_error(GemConfig::InvalidKeyError)
|
147
147
|
end
|
148
148
|
|
149
149
|
it 'does not raise an error if :values are defined the the value is included in them' do
|
150
150
|
subject.has :foo, values: ['foo', 'bar']
|
151
151
|
expect do
|
152
152
|
subject.check :foo, 'foo'
|
153
|
-
end.to_not raise_error(GemConfig::
|
153
|
+
end.to_not raise_error(GemConfig::InvalidKeyError)
|
154
154
|
end
|
155
155
|
end
|
156
156
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gem_config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Manuel Meurer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 2.13.0
|
41
41
|
description: A nifty way to make your gem configurable.
|
42
|
-
email: manuel
|
42
|
+
email: manuel@krautcomputing.com
|
43
43
|
executables: []
|
44
44
|
extensions: []
|
45
45
|
extra_rdoc_files: []
|
@@ -80,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
80
|
version: '0'
|
81
81
|
requirements: []
|
82
82
|
rubyforge_project:
|
83
|
-
rubygems_version: 2.0
|
83
|
+
rubygems_version: 2.2.0
|
84
84
|
signing_key:
|
85
85
|
specification_version: 4
|
86
86
|
summary: A nifty way to make your gem configurable.
|