Class: Ruboty::Handlers::Base

Inherits:
Object
  • Object
show all
Extended by:
Mem
Includes:
Env::Validatable
Defined in:
lib/ruboty/handlers/base.rb

Direct Known Subclasses

Help, Ping, Whoami

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Env::Validatable

#validate, #validate!

Constructor Details

#initialize(robot) ⇒ Base

Returns a new instance of Base.



25
26
27
28
# File 'lib/ruboty/handlers/base.rb', line 25

def initialize(robot)
  @robot = robot
  validate!
end

Instance Attribute Details

#robotObject (readonly)

Returns the value of attribute robot.



23
24
25
# File 'lib/ruboty/handlers/base.rb', line 23

def robot
  @robot
end

Class Method Details

.actionsObject



15
16
17
# File 'lib/ruboty/handlers/base.rb', line 15

def actions
  []
end

.inherited(child) ⇒ Object



7
8
9
# File 'lib/ruboty/handlers/base.rb', line 7

def inherited(child)
  Ruboty.handlers << child
end

.on(pattern, options = {}) ⇒ Object



11
12
13
# File 'lib/ruboty/handlers/base.rb', line 11

def on(pattern, options = {})
  actions << Action.new(pattern, options)
end

Instance Method Details

#call(message, options = {}) ⇒ Object



30
31
32
33
34
# File 'lib/ruboty/handlers/base.rb', line 30

def call(message, options = {})
  self.class.actions.inject(false) do |matched, action|
    matched | action.call(self, message, options)
  end
end