lib/og/store.rb in og-0.24.0 vs lib/og/store.rb in og-0.25.0

- old
+ new

@@ -1,31 +1,31 @@ module Og # A Store is responsible for the peristance of the ObjectGraph. class Store - + # Options. - + attr_accessor :options - + # Transaction nesting. - + attr_accessor :transaction_nesting # :section: Store methods. # Return the store for the given name. def self.for_name(name) # gmosx: to keep RDoc happy. - eval %{ + eval %{ require 'og/store/#{name}' return #{name.to_s.capitalize}Store } end - + # Creates a store. def self.create(options) end @@ -42,15 +42,15 @@ @options = options @transaction_nesting = 0 end # Close the session to the store. - + def close end - # Enchants a class. + # Enchants a class. def enchant(klass, manager) klass.class.send(:define_method, :index) do |arg| meta :index, arg end @@ -65,40 +65,19 @@ def unsaved? return !#{klass.primary_key.symbol} end # Evaluate an alias for the primary key. - + alias_method :pk, :#{pk} alias_method :pk=, :#{pk}= - + def self.pk_symbol :#{klass.primary_key.symbol} end } - # Generate finder methods. - - code = '' - - for p in klass.properties.values - # gmosx: :uniq does NOT set a unique constraint in the - # database. - finder = p.uniq || p.unique ? 'find_one' : 'find' - - code << %{ - def self.find_by_#{p}(val, operator = '=', options = {}) - options.update( - :class => #{klass}, - :condition => "#{p.field || p}\#{operator}\#{ogmanager.store.quote(val)}" - ) - ogmanager.store.#{finder}(options) - end; - } - end - - klass.module_eval(code) end # :section: Lifecycle methods. # Loads an object from the store using the primary key. @@ -111,11 +90,11 @@ def reload(obj) end # Save an object to store. Insert if this is a new object or # update if this is already inserted in the database. - + def save(obj, options = nil) if obj.saved? obj.og_update(self, options) else obj.og_insert(self) @@ -135,18 +114,18 @@ obj.og_update(self, options) end # Update selected properties of an object or class of # objects. - + def update_properties(obj_or_class, props, options = nil) end alias_method :pupdate, :update_properties alias_method :update_property, :update_properties - + # Permanently delete an object from the store. - + def delete(obj_or_pk, klass = nil, cascade = true) unless obj_or_pk.is_a?(EntityMixin) # create a dummy instance to keep the og_delete # method as an instance method like the other lifecycle # methods. @@ -155,47 +134,47 @@ obj_or_pk.og_delete(self, nil, cascade) end end # Perform a query. - + def find(klass, options) end # Count the results returned by the query. - + def count(options) end - + # :section: Transaction methods. - + # Start a new transaction. - + def start raise 'Not implemented' true if @transaction_nesting < 1 @transaction_nesting += 1 end - + # Commit a transaction. - + def commit raise 'Not implemented' @transaction_nesting -= 1 true if @transaction_nesting < 1 end - + # Rollback a transaction. - + def rollback @transaction_nesting -= 1 true if @transaction_nesting < 1 end # Transaction helper. In the transaction block use # the db pointer to the backend. - + def transaction(&block) begin start yield(self) commit @@ -218,10 +197,10 @@ def eval_og_read(klass) end def eval_og_delete(klass) end - + def eval_og_create_schema(klass) end end end