Sha256: 4ccbb6aa488b91115cce202de0846dce618303aae07d0a3e261bd4609629a5df
Contents?: true
Size: 1.33 KB
Versions: 2
Compression:
Stored size: 1.33 KB
Contents
# frozen_string_literal: true module LightweightAttributes module BaseMethods def attributes_before_type_cast @attributes end def read_attribute_before_type_cast(attr_name) @attributes[attr_name] end 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 #NOTE: Should be true for user posted Time Hash, but who cares? def attribute_came_from_user?(_attribute_name) false end def will_save_change_to_attribute?(attr_name, **options) changed_attributes.key? attr_name end def attribute_in_database(attr_name) changed_attributes.key?(attr_name) ? changed_attributes[attr_name] : @attributes[attr_name] end def changes_to_save changed_attributes.each_with_object({}) {|(k, v), h| h[k] = [v, @attributes[k]]} end def changed_attribute_names_to_save changed_attributes.keys end def has_changes_to_save? changed_attributes.any? end def changed_attributes @changed_attributes ||= {} end def changed?(attr_name, **_options) changed_attributes.key? attr_name end private def forget_attribute_assignments @changed_attributes.clear end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
lightweight_attributes-0.1.1 | lib/lightweight_attributes/base_methods.rb |
lightweight_attributes-0.1.0 | lib/lightweight_attributes/base_methods.rb |