Module: Commutator::Model
- Extended by:
- ActiveSupport::Concern
- Includes:
- ActiveModel::Model, Attributes, Hooks, TableConfiguration
- Defined in:
- lib/commutator/model.rb,
lib/commutator/model/hooks.rb,
lib/commutator/model/attributes.rb,
lib/commutator/model/table_configuration.rb
Overview
Basic CRUD wrapper for items in a dynamodb table.
This module is focused on collections of homogenous items within a single table.
TODO: support multiple tables
class Person
include Commutator::Model
attribute :first_name,
:last_name,
:email
attribute :age, type: :integer
attribute :favorite_color, writer: false
primary_key hash: :email, range: :age
def favorite_color=(color)
@color = color.downcase
end
end
Defined Under Namespace
Modules: Attributes, ClassMethods, Hooks, TableConfiguration
Instance Method Summary
collapse
Methods included from Hooks
#run_before_hooks
#primary_key_hash, #primary_key_range
Methods included from Attributes
#assign_attributes, #attribute_names, #attributes
Instance Method Details
#==(other) ⇒ Object
98
99
100
101
102
103
|
# File 'lib/commutator/model.rb', line 98
def ==(other)
self.class == other.class &&
primary_key_hash == other.primary_key_hash &&
primary_key_range == other.primary_key_range &&
attributes == other.attributes
end
|
#delete_item(options = nil) ⇒ Object
86
87
88
89
90
91
92
|
# File 'lib/commutator/model.rb', line 86
def delete_item(options = nil)
dynamo_request(:delete_item, options)
return false if errors.present?
@deleted = true
freeze
end
|
#delete_item_options ⇒ Object
72
73
74
|
# File 'lib/commutator/model.rb', line 72
def delete_item_options
self.class.build_options_proxy(:delete_item, self)
end
|
#deleted? ⇒ Boolean
94
95
96
|
# File 'lib/commutator/model.rb', line 94
def deleted?
@deleted == true
end
|
#initialize(attrs = {}) ⇒ Object
60
61
62
|
# File 'lib/commutator/model.rb', line 60
def initialize(attrs = {})
assign_attributes(attrs.symbolize_keys)
end
|
#put_item(options = nil) ⇒ Object
76
77
78
79
|
# File 'lib/commutator/model.rb', line 76
def put_item(options = nil)
dynamo_request(:put_item, options) unless invalid?
errors.empty?
end
|
#put_item_options ⇒ Object
64
65
66
|
# File 'lib/commutator/model.rb', line 64
def put_item_options
self.class.build_options_proxy(:put_item, self)
end
|
#update_item(options = nil) ⇒ Object
81
82
83
84
|
# File 'lib/commutator/model.rb', line 81
def update_item(options = nil)
dynamo_request(:update_item, options) unless invalid?
errors.empty?
end
|
#update_item_options ⇒ Object
68
69
70
|
# File 'lib/commutator/model.rb', line 68
def update_item_options
self.class.build_options_proxy(:update_item, self)
end
|