Class: Dynamodb::Base
- Inherits:
-
Object
- Object
- Dynamodb::Base
- Extended by:
- Connection
- Includes:
- AttributeAssignment, Querying
- Defined in:
- lib/dynamodb/base.rb
Constant Summary
Constants included from AttributeAssignment
AttributeAssignment::ATTRIBUTE_TYPES, AttributeAssignment::KEY_TYPES, AttributeAssignment::PROJECTION_TYPES
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Instance Method Summary collapse
- #add_error(e) ⇒ Object
- #generate_timestamps ⇒ Object
- #handle_error(e) ⇒ Object
-
#initialize(data = {}, new_record = true) ⇒ Base
constructor
A new instance of Base.
- #new_record? ⇒ Boolean
- #valid? ⇒ Boolean
Methods included from Connection
client, reset_client, resource
Methods included from Querying
#destroy, included, #save, #update
Methods included from TableActions
#_query, #create_table, #delete_item, #delete_table, #describe_table, #get_item, #list_tables, #put_item
Methods included from AttributeAssignment
#client, #global_indexes, #hash_key, included, #indexes, #local_indexes, #range_key, #table_name
Constructor Details
#initialize(data = {}, new_record = true) ⇒ Base
Returns a new instance of Base.
22 23 24 25 26 |
# File 'lib/dynamodb/base.rb', line 22 def initialize(data = {}, new_record = true) self.data = data @new_record = new_record @errors = [] end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
19 20 21 |
# File 'lib/dynamodb/base.rb', line 19 def data @data end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
20 21 22 |
# File 'lib/dynamodb/base.rb', line 20 def errors @errors end |
Instance Method Details
#add_error(e) ⇒ Object
57 58 59 |
# File 'lib/dynamodb/base.rb', line 57 def add_error(e) @errors << e end |
#generate_timestamps ⇒ Object
61 62 63 64 65 |
# File 'lib/dynamodb/base.rb', line 61 def self&.schedule_time_to_live @data["updated_at"] = Time.now.utc.iso8601 @data["created_at"] = Time.now.utc.iso8601 if new_record? end |
#handle_error(e) ⇒ Object
53 54 55 |
# File 'lib/dynamodb/base.rb', line 53 def handle_error(e) @errors << e. end |
#new_record? ⇒ Boolean
37 38 39 |
# File 'lib/dynamodb/base.rb', line 37 def new_record? @new_record.nil? ? false : @new_record end |
#valid? ⇒ Boolean
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/dynamodb/base.rb', line 41 def valid? # Checks to make sure the data is in the proper format and includes the # hash_key Primary Key, and range_key if has one # TODO need to validate data is a hash earlier # @data = 'a string' @errors = [] # start fresh return true if valid_data_format? && valid_hash_key? && valid_range_key? @errors << "Incorrect format of data" false # is not valid end |