Class: Jace::Handler Private

Inherits:
Object
  • Object
show all
Defined in:
lib/jace/handler.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Handler that will be executed once an event has been triggerd

Handler will use the given method name or block to execute some code within the given context

Author:

  • Darthjee

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method_name) ⇒ Handler #initialize(block) ⇒ Handler #initialize(&block) ⇒ Handler

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Handler.

Overloads:

  • #initialize(method_name) ⇒ Handler

    Parameters:

    • method_name (Symbol)

      method to be called in context

  • #initialize(block) ⇒ Handler

    Parameters:

    • block (Proc)

      block object to be called within context

  • #initialize(&block) ⇒ Handler

    Parameters:

    • block (Proc)

      block to be called within context



20
21
22
23
24
25
26
27
28
# File 'lib/jace/handler.rb', line 20

def initialize(method_name = nil, &block)
  if block
    @block = block if block
  elsif method_name.is_a?(Proc)
    @block = method_name
  else
    @block = proc { send(method_name) }
  end
end

Instance Attribute Details

#blockObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



12
13
14
# File 'lib/jace/handler.rb', line 12

def block
  @block
end

Instance Method Details

#call(context) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



30
31
32
# File 'lib/jace/handler.rb', line 30

def call(context)
  context.instance_eval(&block)
end

#to_procObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



34
35
36
37
# File 'lib/jace/handler.rb', line 34

def to_proc
  handler = self
  proc { |context| handler.call(context) }
end