Module: Reorm::EventSource

Includes:
EventData
Included in:
Model
Defined in:
lib/reorm/modules/event_modules.rb

Overview

A module that is used to provide the methods the create events.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(target) ⇒ Object



94
95
96
# File 'lib/reorm/modules/event_modules.rb', line 94

def EventSource.included(target)
  target.extend(EventSource)
end

Instance Method Details

#fire_events(settings = {}) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/reorm/modules/event_modules.rb', line 74

def fire_events(settings={})
  events = settings[:events]
  if events && !events.empty?
    object   = (settings[:target] ? settings[:target] : self)
    handlers = @@class_events[self.instance_of?(Class) ? self : self.class]
    if handlers && !handlers.empty?
      events.each do |event|
        if handlers.include?(event)
          handlers[event].each do |handler|
            if !object.respond_to?(handler, true)
              raise Error, "Unable to locate a method called '#{handler}' for an instance of the #{object.class.name} class."
            end
            object.__send__(handler)
          end
        end
      end
    end
  end
end