Class: Core::Operation::Compiler

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

Overview

public

Compiles an operation into evalable code.

Class Method Summary collapse

Class Method Details

.compile(callable, object) ⇒ Object

public

Compiles a callable operation in context of an object.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/core/operation/compiler.rb', line 13

def compile(callable, object)
  compiled = <<~CODE
    #{compile_actions(callable, object)}
    def invoke(object, name, ...)
      __send__(name, object, ...)
    end
  CODE

  unless callable.actions.any? { |action| action.name == :call }
    compiled << <<~CODE
      def call(...)
        raise UndefinedActionError, "undefined action `call`"
      end
    CODE
  end

  compiled
end