lib/has_eav.rb in has_eav-1.1.4 vs lib/has_eav.rb in has_eav-1.1.5
- old
+ new
@@ -32,11 +32,11 @@
#
def has_eav opts={}, &block
klass = opts.delete :through
klass = klass.to_s if klass.is_a? Symbol
klass = klass.camelize
-
+
raise(
"Eav Class cannot be nil. Specify a class using " +
"has_eav :through => :class"
) if klass.blank?
@@ -114,17 +114,17 @@
if attribute
if !value.nil?
return attribute.send(:write_attribute, "value", value)
else
- @eav_attributes -= [ attribute ]
+ self.eav_attributes -= [ attribute ]
return attribute.destroy
end
elsif !value.nil?
- @eav_attributes << eav_class.new(
+ self.eav_attributes << eav_class.new(
:name => attribute_name,
:value => "#{value}"
)
return cast_eav_value(value, attribute_name)
@@ -219,21 +219,16 @@
# for core types [eg: Integer '12']
eval("#{attributes[attribute]} '#{value}'")
rescue
begin
- # for BigDecimal [eg: BigDecimal.new("123.45")]
- eval("#{attributes[attribute]}.new('#{value}')")
-
+ attributes[attribute].new(value)
rescue
begin
- # for date/time classes [eg: Date.parse("2011-03-20")]
- eval("#{attributes[attribute]}.parse('#{value}')")
+ attributes[attribute].parse(value)
rescue
- # nothing worked, falling back to whatever the ORM supplied
value
end
-
end
end
end
protected :save_eav_attributes, :self_key, :cast_eav_value