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 Attribute Summary collapse
- #destroyed ⇒ Object private
- #new_record ⇒ Object private
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
- #destroyed? ⇒ Boolean 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.
- #new_record? ⇒ Boolean private
- #persisted? ⇒ Boolean private
- #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.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/aws-record/record/item_data.rb', line 7 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? @new_record = true @destroyed = false populate_default_values end |
Instance Attribute Details
#destroyed ⇒ 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.
19 20 21 |
# File 'lib/aws-record/record/item_data.rb', line 19 def destroyed @destroyed end |
#new_record ⇒ 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.
19 20 21 |
# File 'lib/aws-record/record/item_data.rb', line 19 def new_record @new_record 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.
71 72 73 |
# File 'lib/aws-record/record/item_data.rb', line 71 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.
58 59 60 61 62 63 64 65 |
# File 'lib/aws-record/record/item_data.rb', line 58 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.
67 68 69 |
# File 'lib/aws-record/record/item_data.rb', line 67 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.
98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/aws-record/record/item_data.rb', line 98 def build_save_hash @data.each_with_object({}) do |name_value_pair, acc| 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.
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/aws-record/record/item_data.rb', line 45 def clean! @dirty_flags = {} @model_attributes.attributes.each_key do |name| populate_default_values value = get_attribute(name) @clean_copies[name] = if @track_mutations _deep_copy(value) else value end end end |
#destroyed? ⇒ 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.
33 34 35 |
# File 'lib/aws-record/record/item_data.rb', line 33 def destroyed? @destroyed 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.
75 76 77 78 79 80 |
# File 'lib/aws-record/record/item_data.rb', line 75 def dirty @model_attributes.attributes.keys.each_with_object([]) do |name, acc| 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.
82 83 84 |
# File 'lib/aws-record/record/item_data.rb', line 82 def dirty? !dirty.empty? 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.
21 22 23 |
# File 'lib/aws-record/record/item_data.rb', line 21 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.
94 95 96 |
# File 'lib/aws-record/record/item_data.rb', line 94 def hash_copy @data.dup end |
#new_record? ⇒ 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.
29 30 31 |
# File 'lib/aws-record/record/item_data.rb', line 29 def new_record? @new_record end |
#persisted? ⇒ 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.
37 38 39 |
# File 'lib/aws-record/record/item_data.rb', line 37 def persisted? !(new_record? || destroyed?) 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.
110 111 112 113 114 115 116 117 |
# File 'lib/aws-record/record/item_data.rb', line 110 def populate_default_values @model_attributes.attributes.each do |name, attribute| next if (default_value = attribute.default_value).nil? next unless @data[name].nil? @data[name] = default_value 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.
41 42 43 |
# File 'lib/aws-record/record/item_data.rb', line 41 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.
86 87 88 89 90 91 92 |
# File 'lib/aws-record/record/item_data.rb', line 86 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.
25 26 27 |
# File 'lib/aws-record/record/item_data.rb', line 25 def set_attribute(name, value) @data[name] = value end |