Class: Dynamoid::TransactionWrite::Delete
- Defined in:
- lib/dynamoid/transaction_write/delete.rb
Constant Summary
Constants inherited from Action
Instance Attribute Summary
Attributes inherited from Action
#additions, #attributes, #deletions, #model, #options, #removals
Instance Method Summary collapse
-
#initialize(model_or_model_class, key_or_attributes = {}, options = {}) ⇒ Delete
constructor
a model is not needed since callbacks are not run.
- #to_h ⇒ Object
Methods inherited from Action
#add, #add_timestamps, #changes_applied, #delete, #find_from_attributes, #hash_key, #model_class, #raise_validation_error?, #range_key, #run_callbacks, #sanitize_item, #set, #skip_callbacks?, #skip_validation?, #touch_model_timestamps, #valid?, #write_attributes_to_model
Constructor Details
#initialize(model_or_model_class, key_or_attributes = {}, options = {}) ⇒ Delete
a model is not needed since callbacks are not run
9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/dynamoid/transaction_write/delete.rb', line 9 def initialize(model_or_model_class, key_or_attributes = {}, = {}) = .reverse_merge(skip_validation: true) super(model_or_model_class, {}, ) self.attributes = if key_or_attributes.is_a?(Hash) key_or_attributes else { model_class.hash_key => key_or_attributes } end raise Dynamoid::Errors::MissingHashKey unless hash_key.present? raise Dynamoid::Errors::MissingRangeKey unless !model_class.range_key? || range_key.present? end |
Instance Method Details
#to_h ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/dynamoid/transaction_write/delete.rb', line 23 def to_h key = { model_class.hash_key => hash_key } key[model_class.range_key] = range_key if model_class.range_key? { delete: { key: key, table_name: model_class.table_name } } end |