Module: Dcha::Peer::RemoteExecutable

Included in:
Dcha::Peer
Defined in:
lib/dcha/peer/remote_executable.rb

Overview

:nodoc:

Constant Summary collapse

EXECUTABLE_OBJECT =
%w[trie chain].freeze

Instance Method Summary collapse

Instance Method Details

#execute(action, object_name = nil, params = []) ⇒ Object



7
8
9
10
11
12
# File 'lib/dcha/peer/remote_executable.rb', line 7

def execute(action, object_name = nil, params = [])
  return execute_on(self, action, params) if object_name.nil?
  object = pickup_object(object_name)
  return if object.nil?
  execute_on(object, action, params)
end

#execute_on(object, action, params = []) ⇒ Object



14
15
16
17
# File 'lib/dcha/peer/remote_executable.rb', line 14

def execute_on(object, action, params = [])
  return unless object.respond_to?(action)
  object.send(action, *params)
end

#pickup_object(name) ⇒ Object



19
20
21
22
# File 'lib/dcha/peer/remote_executable.rb', line 19

def pickup_object(name)
  return unless EXECUTABLE_OBJECT.include?(name)
  instance_variable_get("@#{name}")
end