Module: Eco::Language::Methods::DslAble

Included in:
API::Session::Batch::BasePolicy, API::Session::Batch::Job, API::UseCases::BaseIO
Defined in:
lib/eco/language/methods/dsl_able.rb

Overview

Note:
  1. If a method is missing on the evaluation object, it will re-try it on on the block context.
  2. Override behaviour: the above gives precedence to methods defined in the context of the object that evaluates, over those in the block context.

Adds #evaluate, which will run &block where DslAble has been included.

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

When it's the case, redirect to the original evaluate caller



25
26
27
28
29
# File 'lib/eco/language/methods/dsl_able.rb', line 25

def method_missing(method, *args, **kargs, &block)
  super unless @self_before_evaluate

  @self_before_evaluate.send(method, *args, **kargs, &block)
end

Instance Method Details

#evaluate(*args, **kargs, &block) ⇒ Object

Note:

if the object misses any method, redirects the method to the original evaluate caller.

It runs the block within this object context



13
14
15
16
17
18
19
20
21
# File 'lib/eco/language/methods/dsl_able.rb', line 13

def evaluate(*args, **kargs, &block)
  return unless block_given?

  @self_before_evaluate = eval('self', block.binding, __FILE__, __LINE__)

  instance_exec(*args, **kargs, &block).tap do
    @self_before_evaluate = nil
  end
end

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

Note:

that for a Dsl this is not necessary

This allows to capture a method using name method.

Returns:

  • (Boolean)


33
34
35
# File 'lib/eco/language/methods/dsl_able.rb', line 33

def respond_to_missing?(name, include_private = false)
  super
end