Class: Lita::Callback Private

Inherits:
Object
  • Object
show all
Defined in:
lib/lita/callback.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.

Represents the action that is taken when a route or event is triggered. It can be a block or the name of a method on object.

Since:

  • 4.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method_name) ⇒ Callback #initialize(callable) ⇒ Callback

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 Callback.

Overloads:

  • #initialize(method_name) ⇒ Callback

    Parameters:

    • method_name (String, Symbol)

      The name of the instance method that serves as the callback.

  • #initialize(callable) ⇒ Callback

    Parameters:

    • callable (Proc)

      A callable object to use as the callback.

Since:

  • 4.0.0



18
19
20
21
22
23
24
# File 'lib/lita/callback.rb', line 18

def initialize(method_name_or_callable)
  if method_name_or_callable.respond_to?(:call)
    @block = method_name_or_callable
  else
    @method_name = method_name_or_callable
  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.

A block that should be used as the callback.

Since:

  • 4.0.0



8
9
10
# File 'lib/lita/callback.rb', line 8

def block
  @block
end

#method_nameObject (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.

The name of the method in the plugin that should be called as the callback.

Since:

  • 4.0.0



11
12
13
# File 'lib/lita/callback.rb', line 11

def method_name
  @method_name
end

Instance Method Details

#call(host, *args) ⇒ 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.

Invokes the callback.

Since:

  • 4.0.0



27
28
29
30
31
32
33
34
35
# File 'lib/lita/callback.rb', line 27

def call(host, *args)
  if block
    host.instance_exec(*args, &block)
  else
    host.public_send(method_name, *args)
  end

  true
end