Class: RSlack::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/rslack/action.rb

Direct Known Subclasses

CronAction, EchoAction, HelpAction, PingAction

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bot) ⇒ Action

Returns a new instance of Action.



27
28
29
# File 'lib/rslack/action.rb', line 27

def initialize(bot)
  @bot = bot
end

Instance Attribute Details

#botObject (readonly)

Returns the value of attribute bot.



25
26
27
# File 'lib/rslack/action.rb', line 25

def bot
  @bot
end

Class Method Details

.route(regexp, **opts, &block) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rslack/action.rb', line 10

def route(regexp, **opts, &block)
  case callback = opts[:callback]
  when nil  then opts[:callback] = block
  when Proc then nil
  when String, Symbol
    opts[:callback] = lambda { |msg| send(callback, msg) }
  end

  route = OpenStruct.new(**opts.merge(action: self, regexp: regexp))
  RSlack::Bot.register(route)
end

Instance Method Details

#memoryObject



31
32
33
# File 'lib/rslack/action.rb', line 31

def memory
  bot.memory[self.class.name] ||= {}
end