Class: Dynamo::Record::BatchRequest
- Inherits:
-
Object
- Object
- Dynamo::Record::BatchRequest
- Defined in:
- lib/dynamo/record/batch_request.rb
Constant Summary collapse
- MAX_RECORD_SIZE =
400 KB
400_000
Instance Attribute Summary collapse
-
#record ⇒ Object
readonly
Returns the value of attribute record.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #delete_request ⇒ Object
-
#initialize(record, type) ⇒ BatchRequest
constructor
A new instance of BatchRequest.
- #request ⇒ Object
- #request_size ⇒ Object
- #save_request ⇒ Object
- #validate_request_size ⇒ Object
- #validate_type ⇒ Object
Constructor Details
#initialize(record, type) ⇒ BatchRequest
Returns a new instance of BatchRequest.
8 9 10 11 12 13 |
# File 'lib/dynamo/record/batch_request.rb', line 8 def initialize(record, type) @type = type @record = record validate_type validate_request_size end |
Instance Attribute Details
#record ⇒ Object (readonly)
Returns the value of attribute record.
6 7 8 |
# File 'lib/dynamo/record/batch_request.rb', line 6 def record @record end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
6 7 8 |
# File 'lib/dynamo/record/batch_request.rb', line 6 def type @type end |
Instance Method Details
#delete_request ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/dynamo/record/batch_request.rb', line 27 def delete_request { delete_request: { key: record.send(:key_values) } } end |
#request ⇒ Object
15 16 17 |
# File 'lib/dynamo/record/batch_request.rb', line 15 def request @_request ||= send("#{type}_request") end |
#request_size ⇒ Object
35 36 37 |
# File 'lib/dynamo/record/batch_request.rb', line 35 def request_size @_request_size ||= request.to_json.length end |
#save_request ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/dynamo/record/batch_request.rb', line 19 def save_request { put_request: { item: record.send(:_build_item_for_save) } } end |
#validate_request_size ⇒ Object
39 40 41 42 |
# File 'lib/dynamo/record/batch_request.rb', line 39 def validate_request_size return unless request_size > MAX_RECORD_SIZE raise RecordTooLargeError.new(record), 'Record is too large' end |
#validate_type ⇒ Object
44 45 46 47 |
# File 'lib/dynamo/record/batch_request.rb', line 44 def validate_type return if i[save delete].include? type raise UnsupportedRequestTypeError end |