class MongoMapper::Plugins::Associations::Base

Constants

AssociationOptions

Options that should not be considered MongoDB query options/criteria

Attributes

name[R]
options[R]
query_options[R]

Public Class Methods

new(name, options={}, &extension) click to toggle source
# File lib/mongo_mapper/plugins/associations/base.rb, line 11
def initialize(name, options={}, &extension)
  @name, @options, @query_options, @original_options = name.to_sym, {}, {}, options
  options.symbolize_keys!
  options[:extend] = modularized_extensions(extension, options[:extend])
  separate_options_and_conditions
end

Public Instance Methods

as() click to toggle source
# File lib/mongo_mapper/plugins/associations/base.rb, line 62
def as
  @options[:as] || self.name
end
as?() click to toggle source
# File lib/mongo_mapper/plugins/associations/base.rb, line 30
def as?
  !in_foreign_array? && !!@options[:as]
end
autosave?() click to toggle source
# File lib/mongo_mapper/plugins/associations/base.rb, line 79
def autosave?
  raise NotImplementedError
end
class_name() click to toggle source
# File lib/mongo_mapper/plugins/associations/base.rb, line 18
def class_name
  @class_name ||= options[:class_name] || name.to_s.camelize
end
counter_cache?() click to toggle source
# File lib/mongo_mapper/plugins/associations/base.rb, line 50
def counter_cache?
  !!@options[:counter_cache]
end
embeddable?() click to toggle source
# File lib/mongo_mapper/plugins/associations/base.rb, line 42
def embeddable?
  klass.embeddable?
end
foreign_key() click to toggle source
# File lib/mongo_mapper/plugins/associations/base.rb, line 66
def foreign_key
  @options[:foreign_key] || "#{name}_id"
end
in_array?() click to toggle source
# File lib/mongo_mapper/plugins/associations/base.rb, line 34
def in_array?
  !!@options[:in]
end
in_foreign_array?() click to toggle source
# File lib/mongo_mapper/plugins/associations/base.rb, line 38
def in_foreign_array?
  !!@options[:from]
end
ivar() click to toggle source
# File lib/mongo_mapper/plugins/associations/base.rb, line 70
def ivar
  @ivar ||= "@_#{name}"
end
klass() click to toggle source
# File lib/mongo_mapper/plugins/associations/base.rb, line 22
def klass
  @klass ||= options[:class] || class_name.constantize
end
ordered?() click to toggle source
# File lib/mongo_mapper/plugins/associations/base.rb, line 54
def ordered?
  !!@options[:ordered]
end
polymorphic?() click to toggle source
# File lib/mongo_mapper/plugins/associations/base.rb, line 26
def polymorphic?
  !!@options[:polymorphic]
end
proxy_class() click to toggle source

:nocov:

# File lib/mongo_mapper/plugins/associations/base.rb, line 75
def proxy_class
  raise NotImplementedError
end
setup(model) click to toggle source

:nocov:

# File lib/mongo_mapper/plugins/associations/base.rb, line 84
def setup(model)
end
touch?() click to toggle source
# File lib/mongo_mapper/plugins/associations/base.rb, line 46
def touch?
  !!@options[:touch]
end
type_key_name() click to toggle source
# File lib/mongo_mapper/plugins/associations/base.rb, line 58
def type_key_name
  "_type"
end

Private Instance Methods

modularized_extensions(*extensions) click to toggle source
# File lib/mongo_mapper/plugins/associations/base.rb, line 99
def modularized_extensions(*extensions)
  extensions.flatten.compact.map do |extension|
    Proc === extension ? Module.new(&extension) : extension
  end
end
separate_options_and_conditions() click to toggle source
# File lib/mongo_mapper/plugins/associations/base.rb, line 89
def separate_options_and_conditions
  @original_options.each_pair do |key, value|
    if AssociationOptions.include?(key)
      @options[key] = value
    else
      @query_options[key] = value
    end
  end
end