module DuckRecord::AttributeMethods::Write

Public Instance Methods

write_attribute(attr_name, value) click to toggle source

Updates the attribute identified by attr_name with the specified value. Empty strings for Integer and Float columns are turned into nil.

# File lib/duck_record/attribute_methods/write.rb, line 31
def write_attribute(attr_name, value)
  name =
    if self.class.attribute_alias?(attr_name)
      self.class.attribute_alias(attr_name).to_s
    else
      attr_name.to_s
    end

  if self.class.readonly_attributes.include?(name) && attr_readonly_enabled?
    return
  end

  write_attribute_with_type_cast(name, value, true)
end

Private Instance Methods

attribute=(attribute_name, value) click to toggle source

Handle *= for method_missing.

# File lib/duck_record/attribute_methods/write.rb, line 53
def attribute=(attribute_name, value)
  write_attribute(attribute_name, value)
end
write_attribute_with_type_cast(attr_name, value, should_type_cast) click to toggle source
# File lib/duck_record/attribute_methods/write.rb, line 57
def write_attribute_with_type_cast(attr_name, value, should_type_cast)
  attr_name = attr_name.to_s

  if should_type_cast
    @attributes.write_from_user(attr_name, value)
  else
    @attributes.write_cast_value(attr_name, value)
  end

  value
end