Class: Sendbird::RequestHandler::RequestMerger
- Inherits:
-
Object
- Object
- Sendbird::RequestHandler::RequestMerger
- Defined in:
- lib/sendbird/request_handler/request_merger.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#callback ⇒ Object
readonly
Returns the value of attribute callback.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#pending_requests ⇒ Object
readonly
Returns the value of attribute pending_requests.
Class Method Summary collapse
Instance Method Summary collapse
- #append_callbacks(args) ⇒ Object
-
#initialize(pending_requests, method, args, callback) ⇒ RequestMerger
constructor
A new instance of RequestMerger.
- #merge ⇒ Object
- #merge_hash_arguments(args) ⇒ Object
- #merge_rest_of_arguments(args) ⇒ Object
Constructor Details
#initialize(pending_requests, method, args, callback) ⇒ RequestMerger
Returns a new instance of RequestMerger.
9 10 11 12 13 14 |
# File 'lib/sendbird/request_handler/request_merger.rb', line 9 def initialize(pending_requests, method, args, callback) @pending_requests = pending_requests @method = method @args = args @callback = callback end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
8 9 10 |
# File 'lib/sendbird/request_handler/request_merger.rb', line 8 def args @args end |
#callback ⇒ Object (readonly)
Returns the value of attribute callback.
8 9 10 |
# File 'lib/sendbird/request_handler/request_merger.rb', line 8 def callback @callback end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
8 9 10 |
# File 'lib/sendbird/request_handler/request_merger.rb', line 8 def method @method end |
#pending_requests ⇒ Object (readonly)
Returns the value of attribute pending_requests.
8 9 10 |
# File 'lib/sendbird/request_handler/request_merger.rb', line 8 def pending_requests @pending_requests end |
Class Method Details
.call(pending_requests, method, args, callback) ⇒ Object
4 5 6 |
# File 'lib/sendbird/request_handler/request_merger.rb', line 4 def self.call(pending_requests, method, args, callback) new(pending_requests, method, args, callback).merge end |
Instance Method Details
#append_callbacks(args) ⇒ Object
38 39 40 41 |
# File 'lib/sendbird/request_handler/request_merger.rb', line 38 def append_callbacks(args) pending_requests[method][:callback] ||= [] pending_requests[method][:callback] = pending_requests[method][:callback] << callback if callback end |
#merge ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/sendbird/request_handler/request_merger.rb', line 16 def merge pending_requests[method] ||= {} case args when Hash merge_hash_arguments(args) else merge_rest_of_arguments(args) end append_callbacks(args) pending_requests end |
#merge_hash_arguments(args) ⇒ Object
28 29 30 31 |
# File 'lib/sendbird/request_handler/request_merger.rb', line 28 def merge_hash_arguments(args) pending_requests[method][:args] ||= {} pending_requests[method][:args] = pending_requests[method][:args].merge(args) end |
#merge_rest_of_arguments(args) ⇒ Object
33 34 35 36 |
# File 'lib/sendbird/request_handler/request_merger.rb', line 33 def merge_rest_of_arguments(args) pending_requests[method][:args] ||= [] pending_requests[method][:args] = pending_requests[method][:args] << args if args end |