Class: Hyraft::Circuit

Inherits:
Object
  • Object
show all
Defined in:
lib/hyraft/engine/circuit.rb

Instance Method Summary collapse

Constructor Details

#initialize(ports = {}) ⇒ Circuit

Returns a new instance of Circuit.



5
6
7
# File 'lib/hyraft/engine/circuit.rb', line 5

def initialize(ports = {})
  @ports = ports
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

Magic: Automatically route custom methods to execute



10
11
12
13
14
15
16
# File 'lib/hyraft/engine/circuit.rb', line 10

def method_missing(method, *args, &block)
  if respond_to_missing?(method)
    execute(operation: method, params: args.first || {})
  else
    super
  end
end

Instance Method Details

#execute(input = {}) ⇒ Object

Raises:

  • (NotImplementedError)


24
25
26
# File 'lib/hyraft/engine/circuit.rb', line 24

def execute(input = {})
  raise NotImplementedError, "Circuits must implement execute method"
end

#respond_to_missing?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
# File 'lib/hyraft/engine/circuit.rb', line 18

def respond_to_missing?(method, include_private = false)
  # Check if it's a public method defined in the subclass OR
  # if the execute method can handle it
  self.class.public_method_defined?(method) || can_handle_operation?(method)
end