Class: Vorpal::Config::MainConfig
- Inherits:
-
Object
- Object
- Vorpal::Config::MainConfig
- Defined in:
- lib/vorpal/config/main_config.rb
Instance Method Summary collapse
- #add_class_config(class_config) ⇒ Object
- #config_for(clazz) ⇒ Object
- #config_for_db_object(db_object) ⇒ Object
-
#initialize ⇒ MainConfig
constructor
A new instance of MainConfig.
- #initialize_association_configs ⇒ Object
Constructor Details
#initialize ⇒ MainConfig
Returns a new instance of MainConfig.
8 9 10 |
# File 'lib/vorpal/config/main_config.rb', line 8 def initialize @class_configs = [] end |
Instance Method Details
#add_class_config(class_config) ⇒ Object
22 23 24 |
# File 'lib/vorpal/config/main_config.rb', line 22 def add_class_config(class_config) @class_configs << class_config end |
#config_for(clazz) ⇒ Object
12 13 14 15 16 |
# File 'lib/vorpal/config/main_config.rb', line 12 def config_for(clazz) config = @class_configs.detect { |conf| conf.domain_class == clazz } raise Vorpal::ConfigurationNotFound.new("No configuration found for #{clazz}") unless config config end |
#config_for_db_object(db_object) ⇒ Object
18 19 20 |
# File 'lib/vorpal/config/main_config.rb', line 18 def config_for_db_object(db_object) @class_configs.detect { |conf| conf.db_class == db_object.class } end |
#initialize_association_configs ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/vorpal/config/main_config.rb', line 26 def initialize_association_configs association_configs = {} @class_configs.each do |config| (config.has_ones + config.has_manys).each do |association_end_config| associated_class_config = config_for(association_end_config.associated_class) association_end_config.set_class_config(config) association_config = build_association_config(association_configs, associated_class_config, association_end_config.fk, association_end_config.fk_type) association_config.remote_end_config = association_end_config association_config.add_remote_class_config(config) association_end_config.association_config = association_config end config.belongs_tos.each do |association_end_config| associated_class_configs = association_end_config.associated_classes.map(&method(:config_for)) association_config = build_association_config(association_configs, config, association_end_config.fk, association_end_config.fk_type) association_config.local_end_config = association_end_config association_config.add_remote_class_config(associated_class_configs) association_end_config.association_config = association_config end end association_configs.values.each do |association_config| association_config.local_class_config.local_association_configs << association_config association_config.validate end end |