|
attribute_blank = if attributes.has_key?(attribute) |
|
column = self.class.columns_hash[attribute] |
|
if column && column.type == :boolean |
|
attributes[attribute].nil? |
|
else |
|
attributes[attribute].blank? |
|
end |
|
elsif respond_to?(attribute) |
|
send(attribute).nil? |
|
else |
|
instance_variable_get("@#{attribute}").nil? |
|
end |
The above code has a few more edge cases that are missed, specifically with the second two cases in the outer conditional where the attribute is not backed by a database column. The next two cases must account for the same issue (attribute can either be a boolean where false is not 'blank', it's a set value, but false.nil? == true, or a collection that is empty via blank?).
This whole thing should be cleaned up, with perhaps a few comments explaining each case.
See d155ba7#commitcomment-30274475
cc/ @romaind
default_value_for/lib/default_value_for.rb
Lines 159 to 170 in c52d291
The above code has a few more edge cases that are missed, specifically with the second two cases in the outer conditional where the attribute is not backed by a database column. The next two cases must account for the same issue (attribute can either be a boolean where
falseis not 'blank', it's a set value, butfalse.nil? == true, or a collection that is empty viablank?).This whole thing should be cleaned up, with perhaps a few comments explaining each case.
See d155ba7#commitcomment-30274475
cc/ @romaind