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::Mixin
Module Og::ModelMixin
Module Og::MysqlUtils
Module Og::OracleUtils
Module Og::PostgresqlUtils
Module Og::RelationDSL
Module Og::SchemaInheritanceBase
Module Og::SchemaInheritanceClass
Module Og::SqlEnchantmentClassMethods
Module Og::SqlEnchantmentMixin
Module Og::SqlEnchantmentNoPolymorphClassMethods
Module Og::SqlUtils
Module Og::Unmanageable
Class Og::Adapter
Class Og::BelongsTo
Class Og::Blob
Class Og::Collection
Class Og::Fixture
Class Og::Fixtures
Class Og::HasMany
Class Og::HasManyCollection
Class Og::HasOne
Class Og::JoinsMany
Class Og::JoinsManyCollection
Class Og::Manager
Class Og::ManyToMany
Class Og::Model
Class Og::MysqlAdapter
Class Og::OracleAdapter
Class Og::PostgresqlAdapter
Class Og::RefersTo
Class Og::Relation
Class Og::SqlStore
Class Og::SqliteAdapter
Class Og::Store
Class Og::StoreException
| NotNull | = | { :sql => 'NOT NULL' } |
| Null | = | { :sql => 'NULL' } |
| Version | = | "0.50.0" |
| The version. | ||
| LibPath | = | File.dirname(__FILE__) |
| Library path. | ||
| [RW] | manager | The active manager |
| [R] | thread_safe | thread safe state |
Some useful type macros to help when defining properties. You can easily code your own type macros. Just return the array that should be passed to the attr_xxx macros.
Example
attr_accessor :name, VarChar(30)
[ show source ]
# File lib/og/types.rb, line 11
11: def self.VarChar(size)
12: return String, :sql => "VARCHAR(#{size})"
13: end
Helper method.
[ show source ]
# File lib/og.rb, line 184
184: def escape(str)
185: @manager.with_store { |s| s.escape(str) }
186: end
Quote the string.
[ show source ]
# File lib/og.rb, line 190
190: def quote(str)
191: @manager.with_store { |s| s.quote(str) }
192: end
Helper method, useful to initialize Og. If no options are passed, sqlite is selected as the default store.
[ show source ]
# File lib/og.rb, line 140
140: def start(options = Og.manager_options)
141: # Use sqlite as the default adapter.
142:
143: unless options[:adapter] || options[:store]
144: options[:adapter] = :sqlite
145: end
146:
147: # This is a flag a store or manager can use to determine
148: # if it was being called by Og.setup to provide
149: # additional, faster or enhanced functionality.
150:
151: options[:called_by_og_setup] = true if options[:called_by_og_setup].nil?
152:
153: @thread_safe = true
154:
155: m = @manager = Manager.new(options)
156: m.manage_classes(options[:classes])
157:
158: # Allows functionality that requires an initialized
159: # store to be implemented. A vastly superior
160: # method of constructing foreign key constraints is an
161: # example of functionality this provides. Currently
162: # only used by the PostgreSQL store.
163:
164:
165: m.post_setup if options[:called_by_og_setup]
166:
167: return m
168: rescue Exception => ex
169: Logger.error "#{ex.class} in Og.setup:"
170: Logger.error ex.message
171: if $DBG # THINK: is this needed?
172: Logger.error ex.backtrace.join("\n")
173: exit
174: end
175: end
Change thread_safe mode.
[ show source ]
# File lib/og.rb, line 196
196: def thread_safe=(bool)
197: @thread_safe = bool
198: # @manager and @manager.class.managers.each { |m| m.initialize_store }
199: return @thread_safe
200: end