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.
10 11 12 13 14 15 |
# File 'lib/dynamo/record/batch_request.rb', line 10 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.
8 9 10 |
# File 'lib/dynamo/record/batch_request.rb', line 8 def record @record end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
8 9 10 |
# File 'lib/dynamo/record/batch_request.rb', line 8 def type @type end |
Instance Method Details
#delete_request ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/dynamo/record/batch_request.rb', line 29 def delete_request { delete_request: { key: record.send(:key_values) } } end |
#request ⇒ Object
17 18 19 |
# File 'lib/dynamo/record/batch_request.rb', line 17 def request @request ||= send("#{type}_request") end |
#request_size ⇒ Object
37 38 39 |
# File 'lib/dynamo/record/batch_request.rb', line 37 def request_size @request_size ||= request.to_json.length end |
#save_request ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/dynamo/record/batch_request.rb', line 21 def save_request { put_request: { item: record.send(:_build_item_for_save) } } end |
#validate_request_size ⇒ Object
41 42 43 44 45 |
# File 'lib/dynamo/record/batch_request.rb', line 41 def validate_request_size return unless request_size > MAX_RECORD_SIZE raise RecordTooLargeError.new(record), 'Record is too large' end |
#validate_type ⇒ Object
47 48 49 50 51 |
# File 'lib/dynamo/record/batch_request.rb', line 47 def validate_type return if %i[save delete].include? type raise UnsupportedRequestTypeError end |