Class: Core::Operation::Callable

Inherits:
Object
  • Object
show all
Defined in:
lib/core/operation/callable.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(object) ⇒ Callable

Returns a new instance of Callable.



9
10
11
12
13
14
# File 'lib/core/operation/callable.rb', line 9

def initialize(object)
  @object = object
  @actions = []
  @compiled = false
  @compiler = Compiler
end

Instance Attribute Details

#actionsObject (readonly)

Returns the value of attribute actions.



21
22
23
# File 'lib/core/operation/callable.rb', line 21

def actions
  @actions
end

Instance Method Details

#actionObject

public

Defines an action.



31
32
33
34
# File 'lib/core/operation/callable.rb', line 31

def action(...)
  @actions << Action.build(...)
  recompile if compiled?
end

#action?(name) ⇒ Boolean

public

Returns:

  • (Boolean)


38
39
40
# File 'lib/core/operation/callable.rb', line 38

def action?(name)
  @actions.any? { |action| action.name == name.to_sym }
end

#call(object) ⇒ Object

public

Calls the default operation action with the given arguments.



44
45
46
# File 'lib/core/operation/callable.rb', line 44

def call(object, ...)
  finalize.call(object, ...)
end

#finalizeObject

public

Finalizes the operation.



56
57
58
59
60
# File 'lib/core/operation/callable.rb', line 56

def finalize
  compile

  self
end

#initialize_copyObject



16
17
18
19
# File 'lib/core/operation/callable.rb', line 16

def initialize_copy(...)
  @actions = @actions.clone
  super
end

#invoke(object, name) ⇒ Object

public


50
51
52
# File 'lib/core/operation/callable.rb', line 50

def invoke(object, name, ...)
  finalize.invoke(object, name, ...)
end

#relocate(object) ⇒ Object

public

Relocates to another object context.



25
26
27
# File 'lib/core/operation/callable.rb', line 25

def relocate(object)
  @object = object
end