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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e38c07a983ddbdf73d79f7b1f7c613849d552c60
4
- data.tar.gz: 394380642649dbd31e48c5c91350dd0a74aab495
3
+ metadata.gz: 1046dd50da7f348b21c6bfcc3e71903012f82897
4
+ data.tar.gz: 44245b10f3f50bd9edde6414fb25f109bbd5378c
5
5
  SHA512:
6
- metadata.gz: b1fef53ce71a8d421011cfef1c1cd075795488b17fe32e1076dbf5d756f3512ef5e68e3ce66fce120ae07a8c1a6cbc0a1c87a0f986bac773c51d2e37748e5ced
7
- data.tar.gz: 206c1aecd2f2aa37393b05fb69b7ff210c4bef027810cc2f6dbb844e5f07b58061f0f20b981ab56ff8b0786ae031db2b433570438adf9227ac8adee4103df4b7
6
+ metadata.gz: 01e105eeb51018f58561cecaeb4816ba754449488401d58c1544bdbfa145124a4689231014c40fefd66e988b600dd35094cc634bb1c8009d8993801f0ea6c202
7
+ data.tar.gz: 6402a8a2746c3319e2742db56c4f8999a032f18242f9f4b7187583471c8ec641f798e42d4f524926257c43955c6ad68132f9e4e6a7227420672832ab8220e832
@@ -3,5 +3,5 @@ rvm:
3
3
  - 1.9.2
4
4
  - 1.9.3
5
5
  - 2.0.0
6
- - jruby-19mode
7
- - rbx-19mode
6
+ - 2.1.0
7
+ - jruby
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'
@@ -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.meurer@gmail.com'
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'
@@ -1,4 +1,7 @@
1
+ require 'gem_config/version'
2
+
1
3
  module GemConfig
4
+ InvalidKeyError = Class.new(StandardError)
2
5
  end
3
6
 
4
7
  require 'gem_config/rules'
@@ -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
@@ -1,7 +1,5 @@
1
1
  module GemConfig
2
2
  class Rules < Hash
3
- InvalidKeyError = Class.new(StandardError)
4
-
5
3
  def has(key, attrs = {})
6
4
  check_attributes attrs
7
5
  self[key.to_sym] = attrs
@@ -1,3 +1,3 @@
1
1
  module GemConfig
2
- VERSION = '0.2.4'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -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::Rules::InvalidKeyError)
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::Rules::InvalidKeyError
74
+ rescue GemConfig::InvalidKeyError
52
75
  end
53
76
  end.to_not change { subject.foo }.from('bar')
54
77
  end
@@ -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::Rules::InvalidKeyError)
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::Rules::InvalidKeyError)
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::Rules::InvalidKeyError)
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::Rules::InvalidKeyError)
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::Rules::InvalidKeyError)
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.2.4
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: 2013-06-06 00:00:00.000000000 Z
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.meurer@gmail.com
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.2
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.