Class: Hypertube::Core::Handler::RetrieveArrayHandler
- Inherits:
-
AbstractHandler
- Object
- AbstractHandler
- Hypertube::Core::Handler::RetrieveArrayHandler
- Defined in:
- lib/hypertube-ruby-sdk/core/handler/retrieve_array_handler.rb
Class Method Summary collapse
-
.normalize_array_like(response) ⇒ Object
Converts Array, Set, and other array-like values to a plain Array payload.
- .to_nested_payload(items) ⇒ Object
Instance Method Summary collapse
-
#initialize ⇒ RetrieveArrayHandler
constructor
A new instance of RetrieveArrayHandler.
- #process(command) ⇒ Object
Methods inherited from AbstractHandler
Constructor Details
#initialize ⇒ RetrieveArrayHandler
Returns a new instance of RetrieveArrayHandler.
11 12 13 |
# File 'lib/hypertube-ruby-sdk/core/handler/retrieve_array_handler.rb', line 11 def initialize @required_parameters_count = 1 end |
Class Method Details
.normalize_array_like(response) ⇒ Object
Converts Array, Set, and other array-like values to a plain Array payload.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/hypertube-ruby-sdk/core/handler/retrieve_array_handler.rb', line 33 def self.normalize_array_like(response) case response when Array response else if defined?(Set) && response.is_a?(Set) response.to_a end end end |
.to_nested_payload(items) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/hypertube-ruby-sdk/core/handler/retrieve_array_handler.rb', line 44 def self.to_nested_payload(items) items.map do |item| if item.is_a?(Array) Hypertube::Utils::Command.new( Hypertube::Utils::RuntimeNameHt::RUBY, Hypertube::Utils::CommandType::ARRAY, to_nested_payload(item) ) else item end end end |
Instance Method Details
#process(command) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/hypertube-ruby-sdk/core/handler/retrieve_array_handler.rb', line 15 def process(command) validate(command, @required_parameters_count, self.class.name) response = command.payload[0] normalized = self.class.normalize_array_like(response) if normalized Hypertube::Utils::Command.new( Hypertube::Utils::RuntimeNameHt::RUBY, Hypertube::Utils::CommandType::ARRAY, self.class.to_nested_payload(normalized) ) else raise ArgumentError, 'Invalid argument type for Hypertube::Core::Handler::RetrieveArrayHandler. Expected an array.' end end |