Class: Kahuna::Handler

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, &block) ⇒ Handler

Returns a new instance of Handler.



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

def initialize(data, &block)
  @event = Event.new data
  unless event.type == 'user'
    @members = MemberCollection.new data
  end
  @action = block_given? ? block : ->(event, members) {}
end

Instance Attribute Details

#eventObject (readonly)

Returns the value of attribute event.



6
7
8
# File 'lib/kahuna/handler.rb', line 6

def event
  @event
end

#membersObject (readonly)

Returns the value of attribute members.



6
7
8
# File 'lib/kahuna/handler.rb', line 6

def members
  @members
end

Instance Method Details

#execute(&block) ⇒ Object



16
17
18
19
# File 'lib/kahuna/handler.rb', line 16

def execute &block
  block_to_call = block_given? ? block : @action
  block_to_call.call(event, members)
end