class MongoModel::Associations::Base::Definition

Attributes

name[R]
options[R]
owner[R]

Public Class Methods

methods(&block) click to toggle source
# File lib/mongomodel/concerns/associations/base/definition.rb, line 58
def self.methods(&block)
  @methods = Proc.new if block_given?
  @methods
end
new(owner, name, options={}) click to toggle source
# File lib/mongomodel/concerns/associations/base/definition.rb, line 7
def initialize(owner, name, options={})
  @owner, @name, @options = owner, name, options
end
properties() click to toggle source
# File lib/mongomodel/concerns/associations/base/definition.rb, line 53
def self.properties
  @properties = Proc.new if block_given?
  @properties
end

Public Instance Methods

collection?() click to toggle source
# File lib/mongomodel/concerns/associations/base/definition.rb, line 41
def collection?
  true
end
define!() click to toggle source
# File lib/mongomodel/concerns/associations/base/definition.rb, line 15
def define!
  owner.instance_exec(self, &self.class.properties) if self.class.properties
  owner.instance_exec(self, &self.class.methods) if self.class.methods

  self
end
for(instance) click to toggle source
# File lib/mongomodel/concerns/associations/base/definition.rb, line 11
def for(instance)
  association_class.new(self, instance)
end
klass() click to toggle source
# File lib/mongomodel/concerns/associations/base/definition.rb, line 22
def klass
  case options[:class]
  when Class
    options[:class]
  when String
    options[:class].constantize
  else
    name.to_s.classify.constantize
  end
end
polymorphic?() click to toggle source
# File lib/mongomodel/concerns/associations/base/definition.rb, line 37
def polymorphic?
  options[:polymorphic]
end
scope() click to toggle source
# File lib/mongomodel/concerns/associations/base/definition.rb, line 45
def scope
  klass.scoped.apply_finder_options(scope_options)
end
scope_options() click to toggle source
# File lib/mongomodel/concerns/associations/base/definition.rb, line 49
def scope_options
  options.slice(:conditions, :select, :offset, :limit, :order)
end
singular_name() click to toggle source
# File lib/mongomodel/concerns/associations/base/definition.rb, line 33
def singular_name
  name.to_s.singularize
end

Private Instance Methods

association_class() click to toggle source
# File lib/mongomodel/concerns/associations/base/definition.rb, line 64
def association_class
  self.class::Association rescue Base::Association
end