# = Og # # Copyright (c) 2004-2006, George Moschovitis (http://www.gmosx.com) # # Og (http://www.nitroproject.org) is copyrighted free software # 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' require 'glue' require 'glue/logger' require 'glue/validation' require 'glue/configuration' # Og (ObjectGraph) manages Ruby objects and their relations and # provides transparent and efficient object-relational mapping # and querying mechanisms. # # === Property Metadata # # Og defines, reserves and uses the following property # metadata types: # # [+:sql_index+] # Create an sql index for this property. # # [+:unique+] # 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 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.41.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. setting :check_implicit_graph_changes, :default => false, :doc => 'If true, check for implicit changes in the object graph' # If true, only allow reading from the database. Usefull # for maintainance. # WARNING: not implemented yet. setting :read_only_mode, :default => false, :doc => 'If true, only allow reading from the database' # Prepend the following prefix to all generated SQL table names. # Usefull on hosting scenarios where you have to run multiple # web applications/sites on a single database. # # Don't set the table_prefix to nil, or you may face problems # with reserved words on some RDBM systems. For example User # maps to user which is reserved in postgresql). The prefix # should start with an alphanumeric character to be compatible # with all RDBM systems (most notable Oracle). #-- # TODO: move this to the sql store. #++ setting :table_prefix, :default => 'og', :doc => 'Prepend the prefix to all generated SQL table names' # If true, Og tries to create/update the schema in the # data store. For production/live environments set this to # false and only set to true when the object model is # 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' # Enable/dissable thread safe mode. # setting :thread_safe, :default => true, :doc => 'Enable/dissable thread safe mode' # Address of the Og cache (if distributed caching enabled). setting :cache_address, :default => '127.0.0.1', :doc => 'Address of the Og cache' # Port of the Og cache (if distributed caching enabled). setting :cache_port, :default => '9070', :doc => 'Port of the Og cache' # A collection of classes that are unmanageable, ie the manager # should ignore them. setting :unmanageable_classes, :default => [], :doc => 'Explicitly unmanageable classes' # Pseudo type for binary data class Blob; end class << self # The active manager attr_accessor :manager # thread safe state attr_reader :thread_safe # Helper method, useful to initialize Og. # If no options are passed, sqlite is selected # as the default store. def start(options = Og.manager_options) # Use sqlite as the default adapter. unless options[:adapter] || options[:store] options[:adapter] = :sqlite end # 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. options[:called_by_og_setup] = true if options[:called_by_og_setup].nil? @thread_safe = true 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 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) end # Quote the string. def quote(str) @manager.store.quote(str) end # Change thread_safe mode. def thread_safe=(bool) @thread_safe = bool # @manager and @manager.class.managers.each { |m| m.initialize_store } return @thread_safe end end end #-- # gmosx: leave this here. #++ require 'og/manager' require 'og/errors' require 'og/types' require 'og/validation' require 'og/markers'