Class: RetrieveArrayHandler
- Inherits:
-
AbstractHandler
- Object
- AbstractHandler
- 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.
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.
8 9 10 |
# File 'lib/hypertube-ruby-sdk/core/handler/retrieve_array_handler.rb', line 8 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.
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/hypertube-ruby-sdk/core/handler/retrieve_array_handler.rb', line 26 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 |
Instance Method Details
#process(command) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/hypertube-ruby-sdk/core/handler/retrieve_array_handler.rb', line 12 def process(command) validate(command, @required_parameters_count, self.class.name) response = command.payload[0] normalized = self.class.normalize_array_like(response) if normalized Command.new(RuntimeNameHt::RUBY, CommandType::ARRAY, normalized) else raise ArgumentError, 'Invalid argument type for RetrieveArrayHandler. Expected an array.' end end |