Class: CrazyDoll::EventManager

Inherits:
Object
  • Object
show all
Defined in:
lib/crazy_doll/events.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(irc) ⇒ EventManager

Returns a new instance of EventManager.



29
30
31
32
33
# File 'lib/crazy_doll/events.rb', line 29

def initialize(irc)
  @irc = irc
  @irc.event_manager = self
  @events = { :sys => {}, :get => {}, :put => {} }
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



28
29
30
# File 'lib/crazy_doll/events.rb', line 28

def config
  @config
end

#eventsObject (readonly)

Returns the value of attribute events.



28
29
30
# File 'lib/crazy_doll/events.rb', line 28

def events
  @events
end

#ircObject (readonly)

Returns the value of attribute irc.



28
29
30
# File 'lib/crazy_doll/events.rb', line 28

def irc
  @irc
end

Instance Method Details

#fire(type, name, opts = {}, line = '') ⇒ Object



35
36
37
38
39
40
41
# File 'lib/crazy_doll/events.rb', line 35

def fire(type, name, opts = {}, line = '')
  type, name = type.to_sym, name.to_sym
  return false unless [:sys, :get, :put].include?(type)
  @events[type][name] ||= []
  @events[type][name].each { |x| x.call(opts, line) }
  fire(type, :command_message, opts, line) if opts.is_a?(CrazyDoll::Message) and opts.command == 'PRIVMSG' and name != :command_message
end

#register(type, klass, opts) ⇒ Object



43
44
45
46
47
# File 'lib/crazy_doll/events.rb', line 43

def register(type, klass, opts)
  type, name = type.to_sym, opts[:method_name].to_sym
  @events[type][name] ||= []
  @events[type][name] << CrazyDoll::Event.new(klass, opts)
end