lib/has_eav.rb in has_eav-1.1.0 vs lib/has_eav.rb in has_eav-1.1.1

- old
+ new

@@ -106,35 +106,39 @@ if method_name =~ /\=$/ value = args[0] if attribute - if value + if !value.nil? return attribute.send(:write_attribute, "value", value) - elsif value.nil? + else + @eav_attributes -= [ attribute ] return attribute.destroy end - else + elsif !value.nil? @eav_attributes << eav_class.new( :name => attribute_name, :value => "#{value}" ) return cast_eav_value(value, attribute_name) + else + return nil + end elsif method_name =~ /\?$/ return ( attribute and attribute.value == true ) ? true : false else + return nil if attribute and attribute.destroyed? return attribute ? cast_eav_value(attribute.value, attribute_name) : nil - end raise e end @@ -196,9 +200,20 @@ if klass.superclass != ActiveRecord::Base klass = klass.superclass end "#{klass.name.underscore}_id".to_sym + end + + # make sure EAV is included in as_json, to_json and to_xml + # + def serializable_hash options=nil + hash = super + eav_attributes_list.each do |attribute| + hash[attribute] = self.send(attribute) + end + + hash end # cast an eav value to it's desired class def cast_eav_value value, attribute # :nodoc: attributes = self.class_eav_attributes.stringify_keys \ No newline at end of file