Class: Aws::Record::ItemData Private
- Inherits:
-
Object
- Object
- Aws::Record::ItemData
- Defined in:
- lib/aws-record/record/item_data.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Instance Method Summary collapse
- #attribute_dirty!(name) ⇒ Object private
- #attribute_dirty?(name) ⇒ Boolean private
- #attribute_was(name) ⇒ Object private
- #build_save_hash ⇒ Object private
- #clean! ⇒ Object private
- #dirty ⇒ Object private
- #dirty? ⇒ Boolean private
- #get_attribute(name) ⇒ Object private
- #hash_copy ⇒ Object private
-
#initialize(model_attributes, opts) ⇒ ItemData
constructor
private
A new instance of ItemData.
- #populate_default_values ⇒ Object private
- #raw_value(name) ⇒ Object private
- #rollback_attribute!(name) ⇒ Object private
- #set_attribute(name, value) ⇒ Object private
Constructor Details
#initialize(model_attributes, opts) ⇒ ItemData
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of ItemData.
19 20 21 22 23 24 25 26 |
# File 'lib/aws-record/record/item_data.rb', line 19 def initialize(model_attributes, opts) @data = {} @clean_copies = {} @dirty_flags = {} @model_attributes = model_attributes @track_mutations = opts[:track_mutations] @track_mutations = true if opts[:track_mutations].nil? end |
Instance Method Details
#attribute_dirty!(name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
66 67 68 |
# File 'lib/aws-record/record/item_data.rb', line 66 def attribute_dirty!(name) @dirty_flags[name] = true end |
#attribute_dirty?(name) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
53 54 55 56 57 58 59 60 |
# File 'lib/aws-record/record/item_data.rb', line 53 def attribute_dirty?(name) if @dirty_flags[name] true else value = get_attribute(name) value != @clean_copies[name] end end |
#attribute_was(name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
62 63 64 |
# File 'lib/aws-record/record/item_data.rb', line 62 def attribute_was(name) @clean_copies[name] end |
#build_save_hash ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/aws-record/record/item_data.rb', line 93 def build_save_hash @data.inject({}) do |acc, name_value_pair| attr_name, raw_value = name_value_pair attribute = @model_attributes.attribute_for(attr_name) if !raw_value.nil? || attribute.persist_nil? db_name = attribute.database_name acc[db_name] = attribute.serialize(raw_value) end acc end end |
#clean! ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/aws-record/record/item_data.rb', line 40 def clean! @dirty_flags = {} @model_attributes.attributes.each_key do |name| populate_default_values value = get_attribute(name) if @track_mutations @clean_copies[name] = _deep_copy(value) else @clean_copies[name] = value end end end |
#dirty ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
70 71 72 73 74 75 |
# File 'lib/aws-record/record/item_data.rb', line 70 def dirty @model_attributes.attributes.keys.inject([]) do |acc, name| acc << name if attribute_dirty?(name) acc end end |
#dirty? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
77 78 79 |
# File 'lib/aws-record/record/item_data.rb', line 77 def dirty? dirty.empty? ? false : true end |
#get_attribute(name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
28 29 30 |
# File 'lib/aws-record/record/item_data.rb', line 28 def get_attribute(name) @model_attributes.attribute_for(name).type_cast(@data[name]) end |
#hash_copy ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
89 90 91 |
# File 'lib/aws-record/record/item_data.rb', line 89 def hash_copy @data.dup end |
#populate_default_values ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
105 106 107 108 109 110 111 112 113 |
# File 'lib/aws-record/record/item_data.rb', line 105 def populate_default_values @model_attributes.attributes.each do |name, attribute| unless attribute.default_value.nil? if @data[name].nil? && @data[name].nil? @data[name] = attribute.default_value end end end end |
#raw_value(name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
36 37 38 |
# File 'lib/aws-record/record/item_data.rb', line 36 def raw_value(name) @data[name] end |
#rollback_attribute!(name) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
81 82 83 84 85 86 87 |
# File 'lib/aws-record/record/item_data.rb', line 81 def rollback_attribute!(name) if attribute_dirty?(name) @dirty_flags.delete(name) set_attribute(name, attribute_was(name)) end get_attribute(name) end |
#set_attribute(name, value) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
32 33 34 |
# File 'lib/aws-record/record/item_data.rb', line 32 def set_attribute(name, value) @data[name] = value end |