Class: Command
- Inherits:
-
Object
- Object
- Command
- Defined in:
- lib/javonet-ruby-sdk/utils/command.rb
Instance Attribute Summary collapse
-
#command_type ⇒ Object
readonly
Returns the value of attribute command_type.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#runtime_name ⇒ Object
readonly
Returns the value of attribute runtime_name.
Class Method Summary collapse
- .create_array_response(array, runtime_name) ⇒ Object
- .create_reference(guid, runtime_name) ⇒ Object
- .create_response(response, runtime_name) ⇒ Object
Instance Method Summary collapse
- #add_arg_to_payload(argument) ⇒ Object
- #drop_first_payload_argument ⇒ Object
- #eql?(other) ⇒ Boolean (also: #==)
-
#initialize(runtime_name, command_type, *payload) ⇒ Command
constructor
A new instance of Command.
- #prepend_arg_to_payload(arg_command) ⇒ Object
- #to_s ⇒ Object
- #to_string ⇒ Object
Constructor Details
#initialize(runtime_name, command_type, *payload) ⇒ Command
Returns a new instance of Command.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/javonet-ruby-sdk/utils/command.rb', line 9 def initialize(runtime_name, command_type, *payload) @runtime_name = runtime_name @command_type = command_type if payload.empty? @payload = [] elsif payload.size == 1 && payload[0].is_a?(Array) # caller passed a single array -> reuse it (no extra copy) @payload = payload[0] || [] else # varargs or multiple args -> use as provided @payload = payload end end |
Instance Attribute Details
#command_type ⇒ Object (readonly)
Returns the value of attribute command_type.
7 8 9 |
# File 'lib/javonet-ruby-sdk/utils/command.rb', line 7 def command_type @command_type end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
7 8 9 |
# File 'lib/javonet-ruby-sdk/utils/command.rb', line 7 def payload @payload end |
#runtime_name ⇒ Object (readonly)
Returns the value of attribute runtime_name.
7 8 9 |
# File 'lib/javonet-ruby-sdk/utils/command.rb', line 7 def runtime_name @runtime_name end |
Class Method Details
.create_array_response(array, runtime_name) ⇒ Object
32 33 34 |
# File 'lib/javonet-ruby-sdk/utils/command.rb', line 32 def self.create_array_response(array, runtime_name) Command.new(runtime_name, CommandType::ARRAY, array) end |
.create_reference(guid, runtime_name) ⇒ Object
28 29 30 |
# File 'lib/javonet-ruby-sdk/utils/command.rb', line 28 def self.create_reference(guid, runtime_name) Command.new(runtime_name, CommandType::REFERENCE, guid) end |
.create_response(response, runtime_name) ⇒ Object
24 25 26 |
# File 'lib/javonet-ruby-sdk/utils/command.rb', line 24 def self.create_response(response, runtime_name) Command.new(runtime_name, CommandType::VALUE, response) end |
Instance Method Details
#add_arg_to_payload(argument) ⇒ Object
43 44 45 46 |
# File 'lib/javonet-ruby-sdk/utils/command.rb', line 43 def add_arg_to_payload(argument) new_payload = @payload + [argument] Command.new(@runtime_name, @command_type, new_payload) end |
#drop_first_payload_argument ⇒ Object
36 37 38 39 40 41 |
# File 'lib/javonet-ruby-sdk/utils/command.rb', line 36 def drop_first_payload_argument return Command.new(@runtime_name, @command_type, []) if @payload.length <= 1 new_payload = @payload[1..-1] || [] Command.new(@runtime_name, @command_type, new_payload) end |
#eql?(other) ⇒ Boolean Also known as: ==
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/javonet-ruby-sdk/utils/command.rb', line 65 def eql?(other) return true if equal?(other) return false unless other.is_a?(Command) return false unless runtime_name == other.runtime_name && command_type == other.command_type return false unless payload.length == other.payload.length payload.each_with_index do |item, i| return false unless item.eql?(other.payload[i]) end true end |
#prepend_arg_to_payload(arg_command) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/javonet-ruby-sdk/utils/command.rb', line 48 def prepend_arg_to_payload(arg_command) return self if arg_command.nil? new_payload = [arg_command] + @payload Command.new(@runtime_name, @command_type, new_payload) end |
#to_s ⇒ Object
61 62 63 |
# File 'lib/javonet-ruby-sdk/utils/command.rb', line 61 def to_s to_string end |
#to_string ⇒ Object
55 56 57 58 59 |
# File 'lib/javonet-ruby-sdk/utils/command.rb', line 55 def to_string 'Runtime Library: ' + RuntimeNameHandler.get_name(@runtime_name) + ' ' + 'Ruby command type: ' + CommandType.get_name(@command_type).to_s + ' ' + 'with parameters: ' + @payload.to_s end |