lib/active_data/model/attributable.rb in active_data-0.2.0 vs lib/active_data/model/attributable.rb in active_data-0.3.0
- old
+ new
@@ -48,12 +48,11 @@
if attributes_cache.key? name
attributes_cache[name]
else
attribute = self.class._attributes[name]
value = attribute.type_cast @attributes[name]
- use_default = attribute.default_blank? && value.blank? || value.nil?
-
+ use_default = attribute.default_blank? && value.respond_to?(:empty?) ? value.empty? : value.nil?
attributes_cache[name] = use_default ? attribute.default_value(self) : value
end
end
alias_method :[], :read_attribute
@@ -77,11 +76,11 @@
end
def present_attributes
Hash[attribute_names.map do |name|
value = send(name)
- [name, value] if value.present?
- end]
+ [name, value] unless value.respond_to?(:empty?) ? value.empty? : value.nil?
+ end.compact]
end
def attribute_names
@attributes.keys
end