module EventMapper

Constants

VERSION

Attributes

event_blocks[RW]

Public Instance Methods

events() click to toggle source
# File lib/eventmapper.rb, line 6
def events
  @events ||= Hash.new { |h, k| h[k] = [] }
end
events_sync=(bool) click to toggle source
# File lib/eventmapper.rb, line 14
def events_sync=(bool)
  @events_sync = bool
end
events_sync?() click to toggle source
# File lib/eventmapper.rb, line 10
def events_sync?
  @events_sync ||= true
end
fire(event, *args) click to toggle source
# File lib/eventmapper.rb, line 22
def fire(event, *args)
  if args.empty?
    events[event].each do |proc|
      if events_sync?
        proc.call
      else
        Thread.new { proc.call }
      end
    end
  else
    events[event].each do |proc|
      if events_sync?
        proc.call *args
      else
        Thread.new { proc.call *args }
      end
    end
  end
end
on(event, &block) click to toggle source
# File lib/eventmapper.rb, line 18
def on(event, &block)
  events[event] << block
end