attrio
attrio copied to clipboard
Fix reset process when initialize with boolean parameter
if initialize is given false parameter,
Boolean attribute is resetted.
for example, definition like README
module MassAssignment
def initialize(attributes = {})
self.attributes = attributes
end
def attributes=(attributes = {})
attributes.each do |attr,value|
self.send("#{attr}=", value) if self.respond_to?("#{attr}=")
end
end
end
class City
include Attrio
include MassAssignment
define_attributes do
attr :name, String
attr :capital, Boolean
end
end
Object initialization
city = City.new(name: "Osaka", capital: false)
city.capital # => this should be `false`, but this is `nil`
Reason
obj.send("#{group}")[name].reset! if obj.send(name).blank?
false.blank? is true, and attribute is resetted.