Module: Events::EventClassMethods

Defined in:
lib/events.rb

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object

Add code for handeling the dsl on_error,after_error,etc…



54
55
56
57
58
59
60
# File 'lib/events.rb', line 54

def method_missing(sym,*args, &block)
  if sym.to_s.match(/^(on|before|after)_/)
    register_handler(sym.to_s,args.first,&block)
  else
    super
  end
end

Class Method Details

.extended(base) ⇒ Object



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

def self.extended(base)
  @@events ||= {}
end

Instance Method Details

#eventsObject



40
41
42
# File 'lib/events.rb', line 40

def events
  @@events
end

#register_handler(name, lambda = nil, &block) ⇒ Object



48
49
50
51
# File 'lib/events.rb', line 48

def register_handler name,lambda = nil, &block
  @@events[name.to_sym] ||= []
  @@events[name.to_sym] << (lambda || block)
end

#respond_to?(sym) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/events.rb', line 62

def respond_to?(sym)
  sym.to_s.match(/^(on|before|after)_/).nil? == false || super
end