module LightweightAttributes::BaseMethods

Public Instance Methods

_write_attribute(attr_name, value) click to toggle source
# File lib/lightweight_attributes/base_methods.rb, line 13
def _write_attribute(attr_name, value)
  was = @attributes[attr_name]
  changed_attributes[attr_name] = was unless changed_attributes.key? attr_name
  @attributes[attr_name] = value
end
attribute_came_from_user?(_attribute_name) click to toggle source

NOTE: Should be true for user posted Time Hash, but who cares?

# File lib/lightweight_attributes/base_methods.rb, line 25
def attribute_came_from_user?(_attribute_name)
  false
end
attribute_in_database(attr_name) click to toggle source
# File lib/lightweight_attributes/base_methods.rb, line 33
def attribute_in_database(attr_name)
  changed_attributes.key?(attr_name) ? changed_attributes[attr_name] : @attributes[attr_name]
end
attributes_before_type_cast() click to toggle source
# File lib/lightweight_attributes/base_methods.rb, line 5
def attributes_before_type_cast
  @attributes
end
changed?(attr_name, **_options) click to toggle source
# File lib/lightweight_attributes/base_methods.rb, line 53
def changed?(attr_name, **_options)
  changed_attributes.key? attr_name
end
changed_attribute_names_to_save() click to toggle source
# File lib/lightweight_attributes/base_methods.rb, line 41
def changed_attribute_names_to_save
  changed_attributes.keys
end
changed_attributes() click to toggle source
# File lib/lightweight_attributes/base_methods.rb, line 49
def changed_attributes
  @changed_attributes ||= {}
end
changes_to_save() click to toggle source
# File lib/lightweight_attributes/base_methods.rb, line 37
def changes_to_save
  changed_attributes.each_with_object({}) {|(k, v), h| h[k] = [v, @attributes[k]]}
end
has_changes_to_save?() click to toggle source
# File lib/lightweight_attributes/base_methods.rb, line 45
def has_changes_to_save?
  changed_attributes.any?
end
read_attribute_before_type_cast(attr_name) click to toggle source
# File lib/lightweight_attributes/base_methods.rb, line 9
def read_attribute_before_type_cast(attr_name)
  @attributes[attr_name]
end
store_original_attributes() click to toggle source

AR 5.0

# File lib/lightweight_attributes/base_methods.rb, line 65
def store_original_attributes
  forget_attribute_assignments
end
will_save_change_to_attribute?(attr_name, **options) click to toggle source
# File lib/lightweight_attributes/base_methods.rb, line 29
def will_save_change_to_attribute?(attr_name, **options)
  changed_attributes.key? attr_name
end

Private Instance Methods

forget_attribute_assignments() click to toggle source
# File lib/lightweight_attributes/base_methods.rb, line 57
        def forget_attribute_assignments
  @changed_attributes.each do |k, v|
    @attributes[k] = v
  end
  @changed_attributes.clear
end
write_attribute_with_type_cast(attr_name, value, _should_type_cast) click to toggle source

AR 5.0

# File lib/lightweight_attributes/base_methods.rb, line 20
        def write_attribute_with_type_cast(attr_name, value, _should_type_cast)
  _write_attribute attr_name, value
end