smart_properties 1.0.3 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/smart_properties.rb +11 -5
- data/spec/smart_properties_spec.rb +24 -0
- metadata +5 -5
data/lib/smart_properties.rb
CHANGED
@@ -22,7 +22,7 @@
|
|
22
22
|
#
|
23
23
|
module SmartProperties
|
24
24
|
|
25
|
-
VERSION = "1.0
|
25
|
+
VERSION = "1.1.0"
|
26
26
|
|
27
27
|
class Property
|
28
28
|
|
@@ -31,11 +31,17 @@ module SmartProperties
|
|
31
31
|
attr_reader :accepter
|
32
32
|
|
33
33
|
def initialize(name, attrs = {})
|
34
|
+
attrs = attrs.dup
|
35
|
+
|
34
36
|
@name = name.to_sym
|
35
|
-
@default = attrs
|
36
|
-
@converter = attrs
|
37
|
-
@accepter = attrs
|
38
|
-
@required = !!attrs
|
37
|
+
@default = attrs.delete(:default)
|
38
|
+
@converter = attrs.delete(:converts)
|
39
|
+
@accepter = attrs.delete(:accepts)
|
40
|
+
@required = !!attrs.delete(:required)
|
41
|
+
|
42
|
+
unless attrs.empty?
|
43
|
+
raise ArgumentError, "SmartProperties do not support the following configuration options: #{attrs.keys.join(', ')}."
|
44
|
+
end
|
39
45
|
end
|
40
46
|
|
41
47
|
def required=(value)
|
@@ -13,6 +13,30 @@ describe SmartProperties do
|
|
13
13
|
it "should add a .property method" do
|
14
14
|
subject.should respond_to(:property)
|
15
15
|
end
|
16
|
+
|
17
|
+
context "and defining a property with invalid configuration options" do
|
18
|
+
|
19
|
+
it "should raise an error reporting one invalid option when one invalid option was given" do
|
20
|
+
expect {
|
21
|
+
subject.tap do |c|
|
22
|
+
c.instance_eval do
|
23
|
+
property :title, :invalid_option => 'boom'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
}.to raise_error(ArgumentError, "SmartProperties do not support the following configuration options: invalid_option.")
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should raise an error reporting three invalid options when three invalid options were given" do
|
30
|
+
expect {
|
31
|
+
subject.tap do |c|
|
32
|
+
c.instance_eval do
|
33
|
+
property :title, :invalid_option_1 => 'boom', :invalid_option_2 => 'boom', :invalid_option_3 => 'boom'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
}.to raise_error(ArgumentError, "SmartProperties do not support the following configuration options: invalid_option_1, invalid_option_2, invalid_option_3.")
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
16
40
|
|
17
41
|
end
|
18
42
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smart_properties
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-09-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -126,7 +126,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
126
126
|
version: '0'
|
127
127
|
segments:
|
128
128
|
- 0
|
129
|
-
hash:
|
129
|
+
hash: 2267066308945748271
|
130
130
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
131
|
none: false
|
132
132
|
requirements:
|
@@ -135,10 +135,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
135
|
version: '0'
|
136
136
|
segments:
|
137
137
|
- 0
|
138
|
-
hash:
|
138
|
+
hash: 2267066308945748271
|
139
139
|
requirements: []
|
140
140
|
rubyforge_project:
|
141
|
-
rubygems_version: 1.8.
|
141
|
+
rubygems_version: 1.8.19
|
142
142
|
signing_key:
|
143
143
|
specification_version: 3
|
144
144
|
summary: SmartProperties – Ruby accessors on steroids
|