class Troles::Mongoid::Config

Public Class Methods

new(subject_class, options = {}) click to toggle source
Calls superclass method Troles::Common::Config::new
# File lib/troles/adapters/mongoid/config.rb, line 4
def initialize subject_class, options = {}
  super
end

Public Instance Methods

configure_field() click to toggle source
# File lib/troles/adapters/mongoid/config.rb, line 24
def configure_field
  type = case strategy
  when :bit_many
    Integer
  when :string_many
    String
  end
  # field :name, :type => String
  subject_class.send(:field, role_field, type_opts(type)) if type      
end
configure_relation() click to toggle source

more likely, strategy should be part of configuration options directly when Config object is created!

# File lib/troles/adapters/mongoid/config.rb, line 9
def configure_relation
  case strategy
  when :ref_many      
    has_many_for subject_class, :role, :through => join_key 
    
    belongs_to_for join_model, subject_class
    belongs_to_for join_model, object_model

    has_many_for role, subject_class, :through => join_key 
    
  when :embed_many
    embeds_many subject_class, object_model
  end
end
type_opts(type) click to toggle source
# File lib/troles/adapters/mongoid/config.rb, line 35
def type_opts type
  { :type => type }
end

Protected Instance Methods

embeds_many(from, to) click to toggle source
# File lib/troles/adapters/mongoid/config.rb, line 41
def embeds_many from, to
  make_relationship :embeds_many, from, to
end