Sha256: e9cee6dc78bc944771d178910a73affc3144e13f8bd90b28257fd803fe4c3f6a

Contents?: true

Size: 1.24 KB

Versions: 2

Compression:

Stored size: 1.24 KB

Contents

# * George Moschovitis  <gm@navel.gr>
# (c) 2004-2005 Navel, all rights reserved.
# $Id: observer.rb 271 2005-03-07 17:56:45Z gmosx $

module Og

# Classes that include this module can be tracked by 
# Observers. The observer mechanism utilizes duck typing
# so you can attach any class that responds to the
# Og lifycycle callback methods. However, classes extended 
# from the Observer base class are typically used.

module Observable
	def add_observer(*observer)
		for o in observer.flatten
			meta :og_observers, o
			self.og_db.adapter.eval_lifecycle_methods(self, self.og_db)
		end
	end
end

# Observers are attached to managed classes to track their
# Lifecycle.  This way, the 'polution' of the original class 
# with excess responsibility is avoided.
#
# An observer can implement the standard Og lifecycle 
# callbacks:
#
# * og_pre_read
# * og_post_read
# * og_pre_insert
# * og_post_insert
#	* og_pre_update
# * og_post_update
# * og_pre_insert_update
# * og_post_insert_update
# * self.og_pre_delete
#
# Based on code from ActiveRecord (http://www.rubyonrails.com)

class Observer
	include Singleton

	# Attaches the observer to the supplied classes.
	
	def self.observe(*classes)
		for c in classes.flatten
			c.meta :og_observers, self
		end
	end
end

end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
nitro-0.12.0 lib/og/observer.rb
og-0.12.0 lib/og/observer.rb