Class: QueryBatchRequest
- Inherits:
-
Object
- Object
- QueryBatchRequest
- Defined in:
- lib/query_batch_request.rb
Overview
Facilitate Batch updates using the pattern of
filter_query -> objects to update
stub object -> attributes/params to update
Instance Attribute Summary collapse
-
#async ⇒ Object
Boolean whether to run the job asyncronously.
-
#async_cutoff ⇒ Object
Number of records at which process is automatically made async.
-
#cap ⇒ Object
Nil, Integer the max allowed records.
-
#cap_reason ⇒ Object
String, nil the reason the cap is why it is (not required).
-
#filter ⇒ Object
A Queries::<<klass>>::Filter instance.
-
#klass ⇒ Object
String defines the Filter/Model to act on.
- #object_filter_params ⇒ Object
- #object_params ⇒ Object
-
#preview ⇒ Object
Boolean true - rollback changes, can not be used with async.
-
#total_attempted ⇒ Object
Count of the records retured in filter.
Instance Method Summary collapse
- #capped? ⇒ Boolean
-
#initialize(params) ⇒ QueryBatchRequest
constructor
A new instance of QueryBatchRequest.
- #response_params ⇒ Object
- #run_async? ⇒ Boolean
- #stub_response ⇒ Object
- #unprocessable? ⇒ Boolean
Constructor Details
#initialize(params) ⇒ QueryBatchRequest
Returns a new instance of QueryBatchRequest.
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/query_batch_request.rb', line 45 def initialize(params) @async = params[:async] @async_cutoff = params[:async_cutoff] @cap = params[:cap] @cap_reason = params[:cap_reason] @klass = params[:klass] @object_filter_params = params[:object_filter_params] @object_params = params[:object_params] @preview = params[:preview] end |
Instance Attribute Details
#async ⇒ Object
Returns Boolean whether to run the job asyncronously.
21 22 23 |
# File 'lib/query_batch_request.rb', line 21 def async @async end |
#async_cutoff ⇒ Object
Number of records at which process is automatically made async
24 25 26 |
# File 'lib/query_batch_request.rb', line 24 def async_cutoff @async_cutoff end |
#cap ⇒ Object
Returns nil, Integer the max allowed records.
28 29 30 |
# File 'lib/query_batch_request.rb', line 28 def cap @cap end |
#cap_reason ⇒ Object
Returns String, nil the reason the cap is why it is (not required).
32 33 34 |
# File 'lib/query_batch_request.rb', line 32 def cap_reason @cap_reason end |
#filter ⇒ Object
Returns a Queries::<<klass>>::Filter instance.
39 40 41 |
# File 'lib/query_batch_request.rb', line 39 def filter @filter end |
#klass ⇒ Object
Returns String defines the Filter/Model to act on.
36 37 38 |
# File 'lib/query_batch_request.rb', line 36 def klass @klass end |
#object_filter_params ⇒ Object
13 14 15 |
# File 'lib/query_batch_request.rb', line 13 def object_filter_params @object_filter_params end |
#object_params ⇒ Object
8 9 10 |
# File 'lib/query_batch_request.rb', line 8 def object_params @object_params end |
#preview ⇒ Object
Returns Boolean true - rollback changes, can not be used with async.
17 18 19 |
# File 'lib/query_batch_request.rb', line 17 def preview @preview end |
#total_attempted ⇒ Object
Count of the records retured in filter.
Not used in async
43 44 45 |
# File 'lib/query_batch_request.rb', line 43 def total_attempted @total_attempted end |
Instance Method Details
#capped? ⇒ Boolean
92 93 94 95 96 97 98 99 |
# File 'lib/query_batch_request.rb', line 92 def capped? if total_attempted > cap @cap_reason = "Update to more objects than allowed (#{cap}) requested." if cap_reason.blank? return true else false end end |
#response_params ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/query_batch_request.rb', line 76 def response_params { klass:, async:, async_cutoff:, preview:, cap:, cap_reason:, total_attempted: } end |
#run_async? ⇒ Boolean
101 102 103 104 105 |
# File 'lib/query_batch_request.rb', line 101 def run_async? if async_cutoff return total_attempted > async_cutoff end end |
#stub_response ⇒ Object
88 89 90 |
# File 'lib/query_batch_request.rb', line 88 def stub_response BatchResponse.new(response_params) end |
#unprocessable? ⇒ Boolean
60 61 62 |
# File 'lib/query_batch_request.rb', line 60 def unprocessable? object_filter_params.blank? || object_params.blank? || (run_async? && preview) end |