gem_config 0.2.3 → 0.2.4
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 +4 -4
- data/gem_config.gemspec +0 -2
- data/lib/gem_config/rules.rb +4 -3
- data/lib/gem_config/version.rb +1 -1
- data/spec/lib/rules_spec.rb +60 -52
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e38c07a983ddbdf73d79f7b1f7c613849d552c60
|
4
|
+
data.tar.gz: 394380642649dbd31e48c5c91350dd0a74aab495
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1fef53ce71a8d421011cfef1c1cd075795488b17fe32e1076dbf5d756f3512ef5e68e3ce66fce120ae07a8c1a6cbc0a1c87a0f986bac773c51d2e37748e5ced
|
7
|
+
data.tar.gz: 206c1aecd2f2aa37393b05fb69b7ff210c4bef027810cc2f6dbb844e5f07b58061f0f20b981ab56ff8b0786ae031db2b433570438adf9227ac8adee4103df4b7
|
data/gem_config.gemspec
CHANGED
data/lib/gem_config/rules.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'active_support/core_ext/hash/keys'
|
2
|
-
|
3
1
|
module GemConfig
|
4
2
|
class Rules < Hash
|
5
3
|
InvalidKeyError = Class.new(StandardError)
|
@@ -24,7 +22,10 @@ module GemConfig
|
|
24
22
|
private
|
25
23
|
|
26
24
|
def check_attributes(attrs)
|
27
|
-
|
25
|
+
allowed_keys = [:classes, :values, :default]
|
26
|
+
attrs.keys.each do |k|
|
27
|
+
raise ArgumentError, %("#{k}" is not a valid attribute. Valid attributes are: #{allowed_keys.join(', ')}) unless allowed_keys.include?(k)
|
28
|
+
end
|
28
29
|
|
29
30
|
if attrs.has_key?(:classes)
|
30
31
|
other_than_class = Array(attrs[:classes]).any? do |value|
|
data/lib/gem_config/version.rb
CHANGED
data/spec/lib/rules_spec.rb
CHANGED
@@ -33,78 +33,86 @@ describe GemConfig::Rules do
|
|
33
33
|
end.to raise_error(ArgumentError)
|
34
34
|
end
|
35
35
|
|
36
|
-
describe '
|
37
|
-
it '
|
36
|
+
describe 'parameters' do
|
37
|
+
it 'raises an exception when a not allowed parameter is passed' do
|
38
38
|
expect do
|
39
|
-
subject.has :foo,
|
40
|
-
end.to_not raise_error(ArgumentError)
|
41
|
-
|
42
|
-
expect do
|
43
|
-
subject.has :foo, classes: [String, Numeric]
|
44
|
-
end.to_not raise_error(ArgumentError)
|
45
|
-
|
46
|
-
expect do
|
47
|
-
subject.has :foo, classes: 'foo'
|
39
|
+
subject.has :foo, bar: 'baz'
|
48
40
|
end.to raise_error(ArgumentError)
|
49
41
|
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe 'parameter :values' do
|
53
|
-
context 'when :classes are defined' do
|
54
|
-
it 'only allows values of one of the specified classes' do
|
55
|
-
expect do
|
56
|
-
subject.has :foo, classes: String, values: 'foo'
|
57
|
-
end.to_not raise_error(ArgumentError)
|
58
42
|
|
43
|
+
describe 'parameter :classes' do
|
44
|
+
it 'only allows a class or an array of classes as the value' do
|
59
45
|
expect do
|
60
|
-
subject.has :foo, classes:
|
46
|
+
subject.has :foo, classes: String
|
61
47
|
end.to_not raise_error(ArgumentError)
|
62
48
|
|
63
49
|
expect do
|
64
|
-
subject.has :foo, classes: [String, Numeric]
|
50
|
+
subject.has :foo, classes: [String, Numeric]
|
65
51
|
end.to_not raise_error(ArgumentError)
|
66
52
|
|
67
53
|
expect do
|
68
|
-
subject.has :foo, classes:
|
54
|
+
subject.has :foo, classes: 'foo'
|
69
55
|
end.to raise_error(ArgumentError)
|
70
56
|
end
|
71
57
|
end
|
72
|
-
end
|
73
|
-
|
74
|
-
describe 'parameter :default' do
|
75
|
-
context 'when :classes are defined' do
|
76
|
-
it 'only allows a value of one of the specified classes' do
|
77
|
-
expect do
|
78
|
-
subject.has :foo, classes: String, default: 'foo'
|
79
|
-
end.to_not raise_error(ArgumentError)
|
80
|
-
|
81
|
-
expect do
|
82
|
-
subject.has :foo, classes: Numeric, default: 1
|
83
|
-
end.to_not raise_error(ArgumentError)
|
84
|
-
|
85
|
-
expect do
|
86
|
-
subject.has :foo, classes: [String, Numeric], default: 'foo'
|
87
|
-
end.to_not raise_error(ArgumentError)
|
88
58
|
|
89
|
-
|
90
|
-
|
91
|
-
|
59
|
+
describe 'parameter :values' do
|
60
|
+
context 'when :classes are defined' do
|
61
|
+
it 'only allows values of one of the specified classes' do
|
62
|
+
expect do
|
63
|
+
subject.has :foo, classes: String, values: 'foo'
|
64
|
+
end.to_not raise_error(ArgumentError)
|
65
|
+
|
66
|
+
expect do
|
67
|
+
subject.has :foo, classes: Numeric, values: 1
|
68
|
+
end.to_not raise_error(ArgumentError)
|
69
|
+
|
70
|
+
expect do
|
71
|
+
subject.has :foo, classes: [String, Numeric], values: ['foo', 1]
|
72
|
+
end.to_not raise_error(ArgumentError)
|
73
|
+
|
74
|
+
expect do
|
75
|
+
subject.has :foo, classes: String, values: ['foo', 1]
|
76
|
+
end.to raise_error(ArgumentError)
|
77
|
+
end
|
92
78
|
end
|
93
79
|
end
|
94
80
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
81
|
+
describe 'parameter :default' do
|
82
|
+
context 'when :classes are defined' do
|
83
|
+
it 'only allows a value of one of the specified classes' do
|
84
|
+
expect do
|
85
|
+
subject.has :foo, classes: String, default: 'foo'
|
86
|
+
end.to_not raise_error(ArgumentError)
|
87
|
+
|
88
|
+
expect do
|
89
|
+
subject.has :foo, classes: Numeric, default: 1
|
90
|
+
end.to_not raise_error(ArgumentError)
|
91
|
+
|
92
|
+
expect do
|
93
|
+
subject.has :foo, classes: [String, Numeric], default: 'foo'
|
94
|
+
end.to_not raise_error(ArgumentError)
|
95
|
+
|
96
|
+
expect do
|
97
|
+
subject.has :foo, classes: Numeric, default: 'foo'
|
98
|
+
end.to raise_error(ArgumentError)
|
99
|
+
end
|
100
|
+
end
|
100
101
|
|
101
|
-
|
102
|
-
|
103
|
-
|
102
|
+
context 'when :values are defined' do
|
103
|
+
it 'only allows one of the specified values' do
|
104
|
+
expect do
|
105
|
+
subject.has :foo, values: 'foo', default: 'foo'
|
106
|
+
end.to_not raise_error(ArgumentError)
|
104
107
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
+
expect do
|
109
|
+
subject.has :foo, values: ['foo', 1], default: 1
|
110
|
+
end.to_not raise_error(ArgumentError)
|
111
|
+
|
112
|
+
expect do
|
113
|
+
subject.has :foo, values: ['foo', 1], default: 'bar'
|
114
|
+
end.to raise_error(ArgumentError)
|
115
|
+
end
|
108
116
|
end
|
109
117
|
end
|
110
118
|
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
|
+
version: 0.2.4
|
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-
|
11
|
+
date: 2013-06-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -38,20 +38,6 @@ dependencies:
|
|
38
38
|
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 2.13.0
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: activesupport
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - '>='
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 3.0.0
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - '>='
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 3.0.0
|
55
41
|
description: A nifty way to make your gem configurable.
|
56
42
|
email: manuel.meurer@gmail.com
|
57
43
|
executables: []
|