Class: Ray::DSL::Handler

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

Overview

Used internally to call blocks registered with Ray::DSL::EventListener#on.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type, group, args, block) ⇒ Handler

Returns a new instance of Handler.



5
6
7
# File 'lib/ray/dsl/handler.rb', line 5

def initialize(type, group, args, block)
  @type, @group, @args, @block = type, group, args, block
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



27
28
29
# File 'lib/ray/dsl/handler.rb', line 27

def args
  @args
end

#groupObject (readonly)

Returns the value of attribute group.



26
27
28
# File 'lib/ray/dsl/handler.rb', line 26

def group
  @group
end

#typeObject (readonly)

Returns the value of attribute type.



25
26
27
# File 'lib/ray/dsl/handler.rb', line 25

def type
  @type
end

Instance Method Details

#call(event) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/ray/dsl/handler.rb', line 17

def call(event)
  if @block.arity == 0
    @block.call
  else
    @block.call(*event.args)
  end
end

#match?(event) ⇒ Boolean Also known as: ===

Returns:

  • (Boolean)


9
10
11
12
13
# File 'lib/ray/dsl/handler.rb', line 9

def match?(event)
  return false unless event.type == @type
  return match_args?(event.args) unless @args.empty?
  true
end