Class: Maruto::MagentoConfig
- Inherits:
-
Object
- Object
- Maruto::MagentoConfig
- Includes:
- TSort
- Defined in:
- lib/maruto/magento_config.rb
Instance Method Summary collapse
-
#initialize(magento_root) ⇒ MagentoConfig
constructor
A new instance of MagentoConfig.
- #is_active_module?(name) ⇒ Boolean
- #models ⇒ Object
- #modules ⇒ Object
- #observers ⇒ Object
- #print_module(name) ⇒ Object
- #print_warnings ⇒ Object
- #tsort_each_child(node, &block) ⇒ Object
- #tsort_each_node(&block) ⇒ Object
Constructor Details
#initialize(magento_root) ⇒ MagentoConfig
Returns a new instance of MagentoConfig.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/maruto/magento_config.rb', line 7 def initialize(magento_root) @modules = {} @global_model_groups = {} @global_events_observers = {} @warnings = [] Dir.chdir(magento_root) do # load module definitions Dir.glob('app/etc/modules/*.xml') do |file| f = File.open(file) doc = Nokogiri::XML(f) { |config| config.strict } f.close doc.xpath('//modules/*').each do |node| load_module_definition(file, node) end end # sort modules dependency graph, then load their config modules().each do |mm_name, mm_config| if mm_config[:active] then # check dependencies mm_config[:dependencies].each do |dep| @warnings << "module:#{mm_name} - missing dependency (#{dep})" unless is_active_module?(dep) end # puts mm_name # puts mm_config config_path = "app/code/#{mm_config[:code_pool]}/#{mm_name.gsub(/_/, '/')}/etc/config.xml" if !File.exist?(config_path) # duplicate warning see new code in module_definition.rb # @warnings << "module:#{mm_name} is defined (#{mm_config[:defined]}) but does not exists (#{config_path})" next end f = File.open(config_path) doc = Nokogiri::XML(f) { |config| config.strict } f.close mm_config[:version] = doc.at_xpath("/config/modules/#{mm_name}/version").content if doc.at_xpath("/config/modules/#{mm_name}/version") ########################################################################################## # MODELS doc.xpath('/config/global/models/*').each do |node| load_model(mm_name, node) end if mm_name.start_with? "Mage_" then # special case for Mage_NAME modules: if not defined, fallback to Mage_Model_NAME group_name = mm_name.sub("Mage_", "").downcase if !@global_model_groups.include? group_name then @global_model_groups[group_name] = { :class => "#{mm_name}_Model", :defined => :fallback, } end if !@global_model_groups[group_name][:class] then # TODO warn? => missing dep? @global_model_groups[group_name][:class] = "#{mm_name}_Model" @global_model_groups[group_name][:defined] = :fallback end end end end # modules().each # check if all model_groups have a class attribute # TODO write test @global_model_groups.each do |group_name, model_group| if !model_group[:class] && !group_name.end_with?('_mysql4') then @warnings << "module:#{model_group[:define]} model_group:#{group_name} - missing class attribute for model" end end end # Dir.chdir(magento_root) end |
Instance Method Details
#is_active_module?(name) ⇒ Boolean
103 104 105 |
# File 'lib/maruto/magento_config.rb', line 103 def is_active_module?(name) @modules.include?(name) && @modules[name][:active] end |
#models ⇒ Object
95 96 97 |
# File 'lib/maruto/magento_config.rb', line 95 def models() @global_model_groups end |
#modules ⇒ Object
91 92 93 |
# File 'lib/maruto/magento_config.rb', line 91 def modules() Hash[tsort.map { |name| [name, @modules[name]] }] end |
#observers ⇒ Object
99 100 101 |
# File 'lib/maruto/magento_config.rb', line 99 def observers() @global_events_observers end |
#print_module(name) ⇒ Object
107 108 109 |
# File 'lib/maruto/magento_config.rb', line 107 def print_module(name) puts @modules[name] end |
#print_warnings ⇒ Object
111 112 113 |
# File 'lib/maruto/magento_config.rb', line 111 def print_warnings() puts @warnings end |
#tsort_each_child(node, &block) ⇒ Object
119 120 121 |
# File 'lib/maruto/magento_config.rb', line 119 def tsort_each_child(node, &block) @modules[node][:dependencies].each(&block) end |
#tsort_each_node(&block) ⇒ Object
115 116 117 |
# File 'lib/maruto/magento_config.rb', line 115 def tsort_each_node(&block) @modules.each_key(&block) end |