65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/simple_model/attributes.rb', line 65
def set_attribute(attr,val,opts=nil)
opts ||= fetch_attribute_options(attr)
attr_key = to_attr_key(attr)
if allow_attribute_action?(val,opts)
ab = opts[:allow_blank]
val = fetch_default_value(opts[:default]) unless skip_set_default?(attr,opts,val,ab)
unless (opts[:boolean] ? (!ab && val.blank? && (val != false)) : (!ab && val.blank?))
val = process_on_set(opts[:on_set],val) if opts.has_key?(:on_set)
send("#{attr}_will_change!") if initialized?(attr) && val != attributes[attr_key]
attributes[attr_key] = val
end
val
end
end
|