simple_model 1.2.9 → 1.2.10
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -1
- data/lib/simple_model/attributes.rb +6 -7
- data/lib/simple_model/version.rb +1 -1
- data/spec/attributes_spec.rb +3 -1
- data/spec/simple_model_spec.rb +2 -2
- metadata +1 -1
data/Gemfile
CHANGED
@@ -113,7 +113,7 @@ module SimpleModel
|
|
113
113
|
end
|
114
114
|
|
115
115
|
def alias_attributes
|
116
|
-
@alias_attributes ||=
|
116
|
+
@alias_attributes ||= HashWithIndifferentAccess.new
|
117
117
|
end
|
118
118
|
|
119
119
|
def alias_attributes=alias_attributes
|
@@ -121,13 +121,17 @@ module SimpleModel
|
|
121
121
|
end
|
122
122
|
|
123
123
|
def defined_attributes
|
124
|
-
@defined_attributes ||=
|
124
|
+
@defined_attributes ||= HashWithIndifferentAccess.new
|
125
125
|
end
|
126
126
|
|
127
127
|
def defined_attributes=defined_attributes
|
128
128
|
@defined_attributes = defined_attributes
|
129
129
|
end
|
130
130
|
|
131
|
+
def attribute_defined?(attr)
|
132
|
+
(self.defined_attributes[attr] || self.superclass.respond_to?(:attribute_defined?) && self.superclass.attribute_defined?(attr))
|
133
|
+
end
|
134
|
+
|
131
135
|
# The default settings for a SimpeModel class
|
132
136
|
# Options:
|
133
137
|
# * :on_set - accepts a lambda that is run when an attribute is set
|
@@ -283,11 +287,6 @@ module SimpleModel
|
|
283
287
|
base.attribute_method_suffix '_changed?', '_change', '_will_change!', '_was'
|
284
288
|
base.attribute_method_affix :prefix => 'reset_', :suffix => '!'
|
285
289
|
end
|
286
|
-
base.defined_attributes = self.defined_attributes.merge(base.defined_attributes)
|
287
|
-
base.alias_attributes = self.alias_attributes.merge(base.alias_attributes)
|
288
|
-
base.defined_attributes.each do |attr,options|
|
289
|
-
base.create_attribute_methods([attr],options) #unless base.instance_methods.include?(attr.to_sym)
|
290
|
-
end
|
291
290
|
end
|
292
291
|
end
|
293
292
|
|
data/lib/simple_model/version.rb
CHANGED
data/spec/attributes_spec.rb
CHANGED
@@ -246,7 +246,7 @@ describe SimpleModel::Attributes do
|
|
246
246
|
end
|
247
247
|
end
|
248
248
|
it "should merge defined attributes when class are inhereted" do
|
249
|
-
NewerBase.
|
249
|
+
NewerBase.attribute_defined?(:bar).should be_true
|
250
250
|
n = NewerBase.new
|
251
251
|
n.respond_to?(:bar_will_change!).should be_true
|
252
252
|
end
|
@@ -254,6 +254,8 @@ describe SimpleModel::Attributes do
|
|
254
254
|
it "should defaults that were not initialized should work from parent class" do
|
255
255
|
n = NewerBase.new
|
256
256
|
n.some.should eql(Date.today)
|
257
|
+
n.some = "2012-12-01"
|
258
|
+
n.some.should be_a(Date)
|
257
259
|
n.thing.should eql(Date.today)
|
258
260
|
end
|
259
261
|
|
data/spec/simple_model_spec.rb
CHANGED
@@ -218,8 +218,8 @@ describe SimpleModel do
|
|
218
218
|
|
219
219
|
end
|
220
220
|
it "should merge defined attributes when class are inhereted" do
|
221
|
-
NewTestStuff.
|
222
|
-
NewTestStuff.
|
221
|
+
NewTestStuff.attribute_defined?(:bar).blank?.should be_false
|
222
|
+
NewTestStuff.attribute_defined?(:foo).blank?.should be_false
|
223
223
|
end
|
224
224
|
it "should merge defined attributes when class are inhereted" do
|
225
225
|
TestStuff.new.respond_to?(:bar_will_change!).should be_true
|