Class: Vetinari::Callback

Inherits:
Object
  • Object
show all
Includes:
Celluloid
Defined in:
lib/vetinari/callback.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event, options, proc, container, uuid) ⇒ Callback

Returns a new instance of Callback.



8
9
10
11
12
13
14
# File 'lib/vetinari/callback.rb', line 8

def initialize(event, options, proc, container, uuid)
  @event = event
  @options = options
  @proc = proc
  @container = container
  @uuid = uuid
end

Instance Attribute Details

#container=(value) ⇒ Object (writeonly)

Sets the attribute container

Parameters:

  • value

    the value to set the attribute container to.



6
7
8
# File 'lib/vetinari/callback.rb', line 6

def container=(value)
  @container = value
end

#eventObject (readonly)

Returns the value of attribute event.



5
6
7
# File 'lib/vetinari/callback.rb', line 5

def event
  @event
end

Instance Method Details

#call(env) ⇒ Object



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

def call(env)
  begin
    @proc.call(env) if matching?(env)
  rescue => e
    loggers = @container.bot.config.loggers
    loggers.error "-- #{e.class}: #{e.message}"
    e.backtrace.each { |line| loggers.error("-- #{line}") }
  end
end

#inspectObject



34
35
36
37
38
39
# File 'lib/vetinari/callback.rb', line 34

def inspect
  event   = @event.inspect
  options = @options.inspect
  uuid    = @uuid.inspect
  "#<Callback event=#{event} options=#{options} uuid=#{uuid}>"
end

#removeObject



26
27
28
# File 'lib/vetinari/callback.rb', line 26

def remove
  @container.remove(@event, @uuid)
end

#remove_and_terminateObject



30
31
32
# File 'lib/vetinari/callback.rb', line 30

def remove_and_terminate
  @container.remove(@event, @uuid, true)
end