ns-options 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +0 -2
- data/lib/ns-options/option.rb +4 -4
- data/lib/ns-options/version.rb +1 -1
- data/ns-options.gemspec +2 -2
- data/test/unit/ns-options/option_test.rb +29 -0
- metadata +21 -7
data/Gemfile
CHANGED
data/lib/ns-options/option.rb
CHANGED
@@ -11,7 +11,7 @@ module NsOptions
|
|
11
11
|
self.rules = rules
|
12
12
|
self.value = rules[:default]
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
def value
|
16
16
|
if self.type_class == NsOptions::Option::Boolean
|
17
17
|
@value and @value.actual
|
@@ -21,17 +21,17 @@ module NsOptions
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def value=(new_value)
|
24
|
-
@value = if (new_value.
|
24
|
+
@value = if (new_value.kind_of?(self.type_class)) || new_value.nil?
|
25
25
|
new_value
|
26
26
|
else
|
27
27
|
self.coerce(new_value)
|
28
28
|
end
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
def is_set?
|
32
32
|
self.value.respond_to?(:is_set?) ? self.value.is_set? : !self.value.nil?
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
def required?
|
36
36
|
!!self.rules[:required] || !!self.rules[:require]
|
37
37
|
end
|
data/lib/ns-options/version.rb
CHANGED
data/ns-options.gemspec
CHANGED
@@ -14,6 +14,6 @@ Gem::Specification.new do |gem|
|
|
14
14
|
gem.require_paths = ["lib"]
|
15
15
|
gem.version = NsOptions::VERSION
|
16
16
|
|
17
|
-
gem.add_development_dependency("assert", ["~>0.6
|
18
|
-
|
17
|
+
gem.add_development_dependency("assert", ["~>0.6"])
|
18
|
+
gem.add_development_dependency("assert-mocha", ["~>0.1"])
|
19
19
|
end
|
@@ -187,5 +187,34 @@ class NsOptions::Option
|
|
187
187
|
assert_equal String, subject.type_class
|
188
188
|
end
|
189
189
|
end
|
190
|
+
|
191
|
+
class WithAValueOfTheSameClassTest < BaseTest
|
192
|
+
desc "with a value of the same class"
|
193
|
+
setup do
|
194
|
+
@class = Class.new
|
195
|
+
@option = NsOptions::Option.new(:something, @class)
|
196
|
+
end
|
197
|
+
|
198
|
+
should "use the object passed to it instead of creating a new one" do
|
199
|
+
value = @class.new
|
200
|
+
@option.value = value
|
201
|
+
assert_same value, @option.value
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
class WithAValueKindOfTest < BaseTest
|
206
|
+
desc "with a value is a kind of the class"
|
207
|
+
setup do
|
208
|
+
@class = Class.new
|
209
|
+
@child_class = Class.new(@class)
|
210
|
+
@option = NsOptions::Option.new(:something, @class)
|
211
|
+
end
|
212
|
+
|
213
|
+
should "use the object passed to it instead of creating a new one" do
|
214
|
+
value = @child_class.new
|
215
|
+
@option.value = value
|
216
|
+
assert_same value, @option.value
|
217
|
+
end
|
218
|
+
end
|
190
219
|
|
191
220
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ns-options
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Collin Redding
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-10-26 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
type: :development
|
@@ -29,10 +29,24 @@ dependencies:
|
|
29
29
|
segments:
|
30
30
|
- 0
|
31
31
|
- 6
|
32
|
-
|
33
|
-
version: 0.6.0
|
32
|
+
version: "0.6"
|
34
33
|
version_requirements: *id001
|
35
34
|
name: assert
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
type: :development
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ~>
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 9
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
- 1
|
47
|
+
version: "0.1"
|
48
|
+
version_requirements: *id002
|
49
|
+
name: assert-mocha
|
36
50
|
description: Define and use namespaced options with a clean interface.
|
37
51
|
email:
|
38
52
|
- collin.redding@reelfx.com
|
@@ -98,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
112
|
requirements: []
|
99
113
|
|
100
114
|
rubyforge_project:
|
101
|
-
rubygems_version: 1.8.
|
115
|
+
rubygems_version: 1.8.11
|
102
116
|
signing_key:
|
103
117
|
specification_version: 3
|
104
118
|
summary: Define and use namespaced options with a clean interface.
|