lib/og.rb in og-0.31.0 vs lib/og.rb in og-0.40.0

- old
+ new

@@ -1,14 +1,13 @@ # = Og # # Copyright (c) 2004-2006, George Moschovitis (http://www.gmosx.com) -# Copyright (c) 2004-2006, Navel Ltd (http://www.navel.gr) # # Og (http://www.nitroproject.org) is copyrighted free software -# created and maintained by George Moschovitis (mailto:gm@navel.gr) -# and released under the standard BSD Licence. For details -# consult the file doc/LICENCE. +# created and maintained by George Moschovitis +# (mailto:george.moschovitis@gmail.com) and released under the +# standard BSD Licence. For details consult the file doc/LICENCE. require 'facet/synchash' require 'facet/syncarray' require 'facets/more/aspects' @@ -33,24 +32,28 @@ # This value of the property must be unique. # # === Design # # Og allows the serialization of arbitrary Ruby objects. Just -# mark them as Object (or Array or Hash) in the prop_accessor +# mark them as Object (or Array or Hash) in the attr_accessor # and the engine will serialize a YAML dump of the object. # Arbitrary object graphs are supported too. module Og # The version. - Version = '0.31.0' + Version = '0.40.0' # Library path. LibPath = File.dirname(__FILE__) + # The default setup for Og managers. + + setting :manager_options, :default => { :adapter => :sqlite }, :doc => 'The default setup for Og managers' + # If true, check for implicit changes in the object # graph. For example when you add an object to a parent # the object might be removed from his previous parent. # In this case Og emmits a warning. @@ -83,10 +86,15 @@ # upadated. For debug/development environments this should # stay true for convienience. setting :create_schema, :default => true, :doc => 'If true, Og tries to create/update the schema in the data store' + # If true, Og destroys the schema on startup. Useful while + # developing / debugging. + + setting :destroy_schema, :default => false, :doc => 'If true, Og destroys the schema on startup' + # If true raises exceptions on store errors, usefull when # debugging. For production environments it should probably be # set to false to make the application more fault tolerant. setting :raise_store_exceptions, :default => true, :doc => 'If true raises exceptions on store errors' @@ -123,36 +131,51 @@ # Helper method, useful to initialize Og. # If no options are passed, sqlite is selected # as the default store. - def setup(options = {}) - options={:store => :sqlite}.update(options) - # This is a flag a store or manager can use to determine - # if it was being called by Og.setup to provide - # additional, faster or enhanced functionality. + def start(options = Og.manager_options) + # Use sqlite as the default adapter. + + unless options[:adapter] || options[:store] + options[:adapter] = :sqlite + end - options[:called_by_og_setup] = true if options[:called_by_og_setup].nil? + # This is a flag a store or manager can use to determine + # if it was being called by Og.setup to provide + # additional, faster or enhanced functionality. - @thread_safe = options.fetch(:thread_safe, true) + options[:called_by_og_setup] = true if options[:called_by_og_setup].nil? - m = @manager = Manager.new(options) - m.manage_classes + @thread_safe = true - # Allows functionality that requires a store is - # finalized to be implemented. A vastly superior - # method of constructing foreign key constraints is an - # example of functionality this provides. Currently - # only used by the PostgreSQL store. - - m.post_setup if options[:called_by_og_setup] + m = @manager = Manager.new(options) + m.manage_classes(options[:classes]) + + # Allows functionality that requires an initialized + # store to be implemented. A vastly superior + # method of constructing foreign key constraints is an + # example of functionality this provides. Currently + # only used by the PostgreSQL store. + + m.post_setup if options[:called_by_og_setup] + return m + rescue Exception => ex + Logger.error "#{ex.class} in Og.setup:" + Logger.error ex.message + if $DBG + Logger.error ex.backtrace.join("\n") + exit + end end - alias_method :connect, :setup - alias_method :options=, :setup - alias_method :setup=, :setup - alias_method :start, :setup + + alias run start + alias connect start + # The following is deprecated, used for compatibility. + alias setup start + alias setup= start # Helper method. def escape(str) @manager.store.escape(str) @@ -167,11 +190,11 @@ # Change thread_safe mode. def thread_safe=(bool) @thread_safe = bool # @manager and @manager.class.managers.each { |m| m.initialize_store } - @thread_safe + return @thread_safe end end end @@ -182,7 +205,5 @@ require 'og/manager' require 'og/errors' require 'og/types' require 'og/validation' require 'og/markers' - -# * George Moschovitis <gm@navel.gr>