Class: Troles::Mongoid::Config

Inherits:
Common::Config show all
Defined in:
lib/troles/adapters/mongoid/config.rb

Instance Attribute Summary

Attributes inherited from Common::Config

#generic, #log_on, #orm, #strategy, #subject_class

Attributes included from Common::Config::ClassMethods

#auto_load, #default_orm, #log_on

Instance Method Summary collapse

Methods inherited from Common::Config

#apply_options!, #auto_config, #auto_config?, #configure!, #default_main_field, #generic?, #log_on?, #main_field, #main_field=, #singularity, sub_modules

Methods included from Common::Config::ClassMethods

#auto_config, #auto_config?, #auto_load?, #log_on?

Constructor Details

#initialize(subject_class, options = {}) ⇒ Config

Returns a new instance of Config.



4
5
6
# File 'lib/troles/adapters/mongoid/config.rb', line 4

def initialize subject_class, options = {}
  super
end

Instance Method Details

#configure_fieldObject



24
25
26
27
28
29
30
31
32
33
# 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_relationObject

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



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 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) ⇒ Object



35
36
37
# File 'lib/troles/adapters/mongoid/config.rb', line 35

def type_opts type
  { :type => type }
end