Module: Kernel

Defined in:
lib/ribs.rb,
lib/ribs/repository.rb

Instance Method Summary collapse

Instance Method Details

#R(obj, db = :default) ⇒ Object

Gets a Repository object for the object in question. If the object is a class, the repository returned will be a Repository::Class, otherwise it will be a Repository::Instance. Specifically, what you will get for the class FooBar will be the class Ribs::Repository::DB_default::FooBar and you will get an instance of that class if the object is an instance of FooBar. This allows you to add specific functionality to these repositories. The class Ribs::Repository::DB_default::FooBar will also include Ribs::Repository::FooBar and extend Ribs::Repository::FooBar::ClassMethods so you can add behavior to these that map over all databases.



240
241
242
# File 'lib/ribs/repository.rb', line 240

def R(obj, db=:default)
  Ribs::Repository(obj, db)
end

#Ribs!(user_options = {}, &block) ⇒ Object

The main method for defining a Ribs model object can be used either from inside the class to define it on, or outside by providing a parameter for the class to act on. This gives some flexibility about where definitions should go. The implementation also keeps it open whether the model class is a real class or a singleton class. The end result of calling the Ribs! method will be to generate a definition for a database mapping, based on the information provided inside the optional block. The block will yield an object of type Ribs::Rib.

user_options currently takes these parameters:

  • :on - The class to define this mapping on. Default will be the receiver of the method call.

  • :db - The database to define this mapping for. :default is the default value.

  • :from - The hibernate XML file to fetch mapping information from. By default nil, and currently doesn’t do anything.



94
95
96
97
98
# File 'lib/ribs.rb', line 94

def Ribs!(user_options = {}, &block)
  default_options = {:on => self, :db => :default, :from => nil}
  options = default_options.merge user_options
  Ribs::define_ribs(options[:on], options, &block)
end