smart_properties 1.0.0 → 1.0.1
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.
- data/lib/smart_properties.rb +11 -13
- data/spec/smart_properties_spec.rb +54 -3
- 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.0.1"
|
26
26
|
|
27
27
|
class Property
|
28
28
|
|
@@ -110,12 +110,18 @@ module SmartProperties
|
|
110
110
|
|
111
111
|
##
|
112
112
|
# Returns the list of smart properties that for this class. This
|
113
|
-
# includes the properties
|
113
|
+
# includes the properties that have been defined in the parent classes.
|
114
114
|
#
|
115
115
|
# @return [Array<Property>] The list of properties.
|
116
116
|
#
|
117
117
|
def properties
|
118
|
-
|
118
|
+
@_smart_properties ||= begin
|
119
|
+
parent = if self != SmartProperties
|
120
|
+
(ancestors[1..-1].find { |klass| klass.ancestors.include?(SmartProperties) && klass != SmartProperties })
|
121
|
+
end
|
122
|
+
|
123
|
+
parent ? parent.properties.dup : {}
|
124
|
+
end
|
119
125
|
end
|
120
126
|
|
121
127
|
##
|
@@ -166,18 +172,10 @@ module SmartProperties
|
|
166
172
|
# :required => true
|
167
173
|
#
|
168
174
|
def property(name, options = {})
|
169
|
-
@_smart_properties ||= begin
|
170
|
-
parent = if self != SmartProperties
|
171
|
-
(ancestors[1..-1].find { |klass| klass.ancestors.include?(SmartProperties) && klass != SmartProperties })
|
172
|
-
end
|
173
|
-
|
174
|
-
parent ? parent.properties : {}
|
175
|
-
end
|
176
|
-
|
177
175
|
p = Property.new(name, options)
|
178
176
|
p.define(self)
|
179
|
-
|
180
|
-
|
177
|
+
|
178
|
+
properties[name] = p
|
181
179
|
end
|
182
180
|
protected :property
|
183
181
|
|
@@ -38,6 +38,9 @@ describe SmartProperties do
|
|
38
38
|
klass
|
39
39
|
end
|
40
40
|
|
41
|
+
its(:properties) { should have(1).property }
|
42
|
+
its(:properties) { should have_key(:title) }
|
43
|
+
|
41
44
|
context "instances of this class" do
|
42
45
|
|
43
46
|
klass = subject.call
|
@@ -74,7 +77,47 @@ describe SmartProperties do
|
|
74
77
|
end
|
75
78
|
|
76
79
|
end
|
77
|
-
|
80
|
+
|
81
|
+
context "when subclassed" do
|
82
|
+
|
83
|
+
superklass = subject.call
|
84
|
+
|
85
|
+
subject do
|
86
|
+
Class.new(superklass)
|
87
|
+
end
|
88
|
+
|
89
|
+
its(:properties) { should have(1).property }
|
90
|
+
its(:properties) { should have_key(:title) }
|
91
|
+
|
92
|
+
context "instances of this subclass" do
|
93
|
+
|
94
|
+
klass = subject.call
|
95
|
+
|
96
|
+
subject do
|
97
|
+
klass.new
|
98
|
+
end
|
99
|
+
|
100
|
+
it { should respond_to(:title) }
|
101
|
+
it { should respond_to(:title=) }
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
context "instances of this subclass that have been intialized from a set of attributes" do
|
106
|
+
|
107
|
+
klass = subject.call
|
108
|
+
|
109
|
+
subject do
|
110
|
+
klass.new :title => stub(:to_title => 'Message')
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should have the correct title" do
|
114
|
+
subject.title.should be == 'Message'
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
|
78
121
|
context "when subclassed and extended with a property called text" do
|
79
122
|
|
80
123
|
superklass = subject.call
|
@@ -86,7 +129,11 @@ describe SmartProperties do
|
|
86
129
|
end
|
87
130
|
end
|
88
131
|
end
|
89
|
-
|
132
|
+
|
133
|
+
its(:properties) { should have(2).property }
|
134
|
+
its(:properties) { should have_key(:title) }
|
135
|
+
its(:properties) { should have_key(:text) }
|
136
|
+
|
90
137
|
context "instances of this subclass" do
|
91
138
|
|
92
139
|
klass = subject.call
|
@@ -144,7 +191,11 @@ describe SmartProperties do
|
|
144
191
|
end
|
145
192
|
end
|
146
193
|
end
|
147
|
-
|
194
|
+
|
195
|
+
its(:properties) { should have(2).property }
|
196
|
+
its(:properties) { should have_key(:title) }
|
197
|
+
its(:properties) { should have_key(:type) }
|
198
|
+
|
148
199
|
context "instances of this class" do
|
149
200
|
|
150
201
|
klass = subject.call
|
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.0.1
|
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-05-
|
12
|
+
date: 2012-05-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -125,7 +125,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
125
125
|
version: '0'
|
126
126
|
segments:
|
127
127
|
- 0
|
128
|
-
hash:
|
128
|
+
hash: -2153981449430065049
|
129
129
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
130
130
|
none: false
|
131
131
|
requirements:
|
@@ -134,10 +134,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
134
|
version: '0'
|
135
135
|
segments:
|
136
136
|
- 0
|
137
|
-
hash:
|
137
|
+
hash: -2153981449430065049
|
138
138
|
requirements: []
|
139
139
|
rubyforge_project:
|
140
|
-
rubygems_version: 1.8.
|
140
|
+
rubygems_version: 1.8.19
|
141
141
|
signing_key:
|
142
142
|
specification_version: 3
|
143
143
|
summary: SmartProperties – Ruby accessors on steroids
|