Class: Hypertube::Core::Handler::CreateClassInstanceHandler
- Inherits:
-
AbstractHandler
- Object
- AbstractHandler
- Hypertube::Core::Handler::CreateClassInstanceHandler
show all
- Defined in:
- lib/hypertube-ruby-sdk/core/handler/create_class_instance_handler.rb
Instance Method Summary
collapse
#handle_command, #validate
Constructor Details
Returns a new instance of CreateClassInstanceHandler.
9
10
11
|
# File 'lib/hypertube-ruby-sdk/core/handler/create_class_instance_handler.rb', line 9
def initialize
@required_parameters_count = 1
end
|
Instance Method Details
#create_class_instance(command) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/hypertube-ruby-sdk/core/handler/create_class_instance_handler.rb', line 17
def create_class_instance(command)
validate(command, @required_parameters_count, self.class.name)
if command.payload.length > 1
constructor_arguments = command.payload[1..]
class_instance = command.payload[0].send('new', *constructor_arguments)
else
class_instance = command.payload[0].send('new')
end
class_instance
rescue NoMethodError
methods = command.payload[0].methods
message = "Method 'new' not found in class #{command.payload[0].name}. Available methods:\n"
methods.each { |method_iter| message += "#{method_iter}\n" }
raise Exception, message
end
|
#process(command) ⇒ Object
13
14
15
|
# File 'lib/hypertube-ruby-sdk/core/handler/create_class_instance_handler.rb', line 13
def process(command)
create_class_instance(command)
end
|