maruto 0.0.8 → 0.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,8 @@
1
1
  require 'maruto/base'
2
2
  require 'nokogiri'
3
3
 
4
+ require 'maruto/module_configuration/event_observers'
5
+
4
6
  module Maruto::ModuleConfiguration
5
7
 
6
8
  def self.parse_module_configuration(m)
@@ -45,118 +47,6 @@ module Maruto::ModuleConfiguration
45
47
  warnings
46
48
  end
47
49
 
48
- def self.parse_scoped_event_observers(base_path, xml_node)
49
-
50
- return [],[] if xml_node.nil?
51
-
52
- events = []
53
- warnings = []
54
-
55
- if xml_node.size > 1
56
- warnings << "duplicate element in config.xml (#{base_path})"
57
- end
58
-
59
- xml_node.xpath('events/*').each do |e|
60
- event = {
61
- :name => e.name,
62
- :path => base_path + '/events/' + e.name,
63
- :observers => [],
64
- }
65
-
66
- e.xpath('observers/*').each do |o|
67
- observer = {
68
- :name => o.name,
69
- :path => event[:path] + '/observers/' + o.name,
70
- }
71
- type = o.at_xpath('type').content unless o.at_xpath('type').nil?
72
- observer[:class] = o.at_xpath('class').content unless o.at_xpath('class').nil?
73
- observer[:method] = o.at_xpath('method').content unless o.at_xpath('method').nil?
74
-
75
- # see Mage_Core_Model_App::dispatchEvent
76
- if type.nil?
77
- # default is singleton
78
- observer[:type] = :singleton
79
- elsif type == 'object'
80
- # object is an alias for model
81
- observer[:type] = :model
82
- warnings << "#{observer[:path]}/type 'object' is an alias for 'model'"
83
- elsif /^(disabled|model|singleton)$/ =~ type
84
- observer[:type] = type.to_sym
85
- else
86
- # everything else => default (with warning)
87
- observer[:type] = :singleton
88
- warnings << "#{observer[:path]}/type replaced with 'singleton', was '#{type}' (possible values: 'disabled', 'model', 'singleton', or nothing)"
89
- end
90
-
91
- event[:observers] << observer
92
- end
93
-
94
- events << event
95
- end
96
-
97
- return events, warnings
98
- end
99
-
100
- def self.parse_all_event_observers(m, xml_node)
101
- areas = [:global, :frontend, :adminhtml, :crontab]
102
- events = {}
103
- warnings = []
104
- areas.each do |area|
105
- e, w = parse_scoped_event_observers("/config/#{area}", xml_node.xpath("/config/#{area}"))
106
-
107
- events[area] = e if e.size > 0
108
- warnings.concat w
109
- end
110
- m[:events] = events if events.keys.size > 0
111
-
112
- warnings << "the 'admin' area should not contain events (/config/admin/events)" unless xml_node.at_xpath("/config/admin/events").nil?
113
-
114
- return warnings
115
- end
116
-
117
- def self.collect_scoped_event_observers(area, sorted_modules)
118
- events = Hash.new
119
-
120
- sorted_modules.each do |m|
121
- if m.include? :events and m[:events].include? area then
122
- m[:events][area].each do |event|
123
- event_name = event[:name]
124
- events[event_name] ||= Hash.new
125
- event[:observers].each do |observer|
126
- observer_name = observer[:name]
127
- if events[event_name].include? observer_name then
128
- if observer[:type] != :disabled
129
- add_module_config_warning(m, "event_observer:#{area}/#{event_name}/#{observer_name} - defined in module:#{events[event_name][observer_name][:module]} and redefined in module:#{m[:name]} (use type: disabled instead)")
130
- end
131
- unless m.include? :dependencies and m[:dependencies].include? events[event_name][observer_name][:module]
132
- add_module_config_warning(m, "module:#{m[:name]} should have a dependency on module:#{events[event_name][observer_name][:module]} because of event_observer:#{area}/#{event_name}/#{observer_name}")
133
- end
134
- else
135
- if observer[:type] == :disabled
136
- add_module_config_warning(m, "event_observer:#{area}/#{event_name}/#{observer_name} - cannot disable an inexistant event observer")
137
- end
138
- end
139
- events[event_name][observer_name] = observer
140
- events[event_name][observer_name][:module] = m[:name]
141
- end
142
- end
143
- end
144
- end
145
-
146
- events
147
- end
148
-
149
- def self.collect_event_observers(sorted_modules)
150
- areas = [:global, :frontend, :adminhtml, :crontab]
151
- events = {}
152
-
153
- areas.each do |area|
154
- events[area] = collect_scoped_event_observers(area, sorted_modules)
155
- end
156
-
157
- events
158
- end
159
-
160
50
  private
161
51
 
162
52
  def self.add_module_config_warning(m, msg)
@@ -0,0 +1,115 @@
1
+ module Maruto::ModuleConfiguration
2
+
3
+ def self.parse_scoped_event_observers(base_path, xml_node)
4
+
5
+ return [],[] if xml_node.nil?
6
+
7
+ events = []
8
+ warnings = []
9
+
10
+ if xml_node.size > 1
11
+ warnings << "duplicate element in config.xml (#{base_path})"
12
+ end
13
+
14
+ xml_node.xpath('events/*').each do |e|
15
+ event = {
16
+ :name => e.name,
17
+ :path => base_path + '/events/' + e.name,
18
+ :observers => [],
19
+ }
20
+
21
+ e.xpath('observers/*').each do |o|
22
+ observer = {
23
+ :name => o.name,
24
+ :path => event[:path] + '/observers/' + o.name,
25
+ }
26
+ type = o.at_xpath('type').content unless o.at_xpath('type').nil?
27
+ observer[:class] = o.at_xpath('class').content unless o.at_xpath('class').nil?
28
+ observer[:method] = o.at_xpath('method').content unless o.at_xpath('method').nil?
29
+
30
+ # see Mage_Core_Model_App::dispatchEvent
31
+ if type.nil?
32
+ # default is singleton
33
+ observer[:type] = :singleton
34
+ elsif type == 'object'
35
+ # object is an alias for model
36
+ observer[:type] = :model
37
+ warnings << "#{observer[:path]}/type 'object' is an alias for 'model'"
38
+ elsif /^(disabled|model|singleton)$/ =~ type
39
+ observer[:type] = type.to_sym
40
+ else
41
+ # everything else => default (with warning)
42
+ observer[:type] = :singleton
43
+ warnings << "#{observer[:path]}/type replaced with 'singleton', was '#{type}' (possible values: 'disabled', 'model', 'singleton', or nothing)"
44
+ end
45
+
46
+ event[:observers] << observer
47
+ end
48
+
49
+ events << event
50
+ end
51
+
52
+ return events, warnings
53
+ end
54
+
55
+ def self.parse_all_event_observers(m, xml_node)
56
+ areas = [:global, :frontend, :adminhtml, :crontab]
57
+ events = {}
58
+ warnings = []
59
+ areas.each do |area|
60
+ e, w = parse_scoped_event_observers("/config/#{area}", xml_node.xpath("/config/#{area}"))
61
+
62
+ events[area] = e if e.size > 0
63
+ warnings.concat w
64
+ end
65
+ m[:events] = events if events.keys.size > 0
66
+
67
+ warnings << "the 'admin' area should not contain events (/config/admin/events)" unless xml_node.at_xpath("/config/admin/events").nil?
68
+
69
+ return warnings
70
+ end
71
+
72
+ def self.collect_scoped_event_observers(area, sorted_modules)
73
+ events = Hash.new
74
+
75
+ sorted_modules.each do |m|
76
+ if m.include? :events and m[:events].include? area then
77
+ m[:events][area].each do |event|
78
+ event_name = event[:name]
79
+ events[event_name] ||= Hash.new
80
+ event[:observers].each do |observer|
81
+ observer_name = observer[:name]
82
+ if events[event_name].include? observer_name then
83
+ if observer[:type] != :disabled
84
+ add_module_config_warning(m, "event_observer:#{area}/#{event_name}/#{observer_name} - defined in module:#{events[event_name][observer_name][:module]} and redefined in module:#{m[:name]} (use type: disabled instead)")
85
+ end
86
+ unless m.include? :dependencies and m[:dependencies].include? events[event_name][observer_name][:module]
87
+ add_module_config_warning(m, "module:#{m[:name]} should have a dependency on module:#{events[event_name][observer_name][:module]} because of event_observer:#{area}/#{event_name}/#{observer_name}")
88
+ end
89
+ else
90
+ if observer[:type] == :disabled
91
+ add_module_config_warning(m, "event_observer:#{area}/#{event_name}/#{observer_name} - cannot disable an inexistant event observer")
92
+ end
93
+ end
94
+ events[event_name][observer_name] = observer
95
+ events[event_name][observer_name][:module] = m[:name]
96
+ end
97
+ end
98
+ end
99
+ end
100
+
101
+ events
102
+ end
103
+
104
+ def self.collect_event_observers(sorted_modules)
105
+ areas = [:global, :frontend, :adminhtml, :crontab]
106
+ events = {}
107
+
108
+ areas.each do |area|
109
+ events[area] = collect_scoped_event_observers(area, sorted_modules)
110
+ end
111
+
112
+ events
113
+ end
114
+
115
+ end
@@ -0,0 +1,6 @@
1
+ module Maruto::ModuleConfiguration
2
+
3
+ def self.parse_models(xml_root)
4
+ end
5
+
6
+ end
@@ -92,6 +92,24 @@ class Maruto::Runner < Thor
92
92
  puts "#{name} #{group}"
93
93
  end
94
94
 
95
+ end
96
+
97
+ desc "modules FILTER", "list modules, optionally filtered by event name"
98
+ method_option :magento_root, :aliases => "-m", :default => "."
99
+ def modules(filter = nil)
100
+
101
+ magento_root = check_magento_folder()
102
+
103
+ magento = Maruto::MagentoInstance.load(magento_root)
104
+
105
+
106
+ magento[:all_modules].each do |name, m|
107
+ if filter.nil? or name.to_s.include? filter
108
+ deps = ''
109
+ deps = ", dependencies:[#{m[:dependencies].collect{ |d| d.to_s }.join(', ')}]" if m[:dependencies]
110
+ puts "#{name}(active:#{m[:active]}, code_pool:#{m[:code_pool]}, defined:#{m[:defined]}#{deps})"
111
+ end
112
+ end
95
113
 
96
114
  end
97
115
 
@@ -1,3 +1,3 @@
1
1
  module Maruto
2
- VERSION = "0.0.8"
2
+ VERSION = "0.0.9"
3
3
  end
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ require 'maruto/module_configuration'
4
+
5
+ module Maruto
6
+
7
+ describe ModuleConfiguration do
8
+
9
+
10
+ describe "when parsing a module config.xml and reading models" do
11
+
12
+ before do
13
+ @xml_root = Nokogiri::XML('''
14
+ <config>
15
+ <global>
16
+ <models>
17
+ <something>
18
+ <class>Mage_A_Model</class>
19
+ </something>
20
+ </models>
21
+ </global>
22
+ </config>
23
+ ''').root
24
+ end
25
+
26
+ # it "will return an array of models and an array of warnings" do
27
+ # no_models = Nokogiri::XML('<config></config>').root
28
+ # models, warnings = ModuleConfiguration.parse_models(no_models)
29
+ # models.must_be_kind_of Array
30
+ # models.size.must_equal 0
31
+ # warnings.must_be_kind_of Array
32
+ # warnings.size.must_equal 0
33
+ # end
34
+ # it "will return an array of models and an array of warnings" do
35
+ # no_models = Nokogiri::XML('<config></config>').root
36
+ # models, warnings = ModuleConfiguration.parse_models(no_models)
37
+ # models.must_be_kind_of Array
38
+ # models.size.must_equal 0
39
+ # warnings.must_be_kind_of Array
40
+ # warnings.size.must_equal 0
41
+ # end
42
+ it "will add a warning if there is a <models> element outside of /config/global" do
43
+ # TODO
44
+ end
45
+ end
46
+ end
47
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maruto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-05-21 00:00:00.000000000 Z
12
+ date: 2013-06-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri
@@ -112,6 +112,8 @@ files:
112
112
  - fixtures/magento_1.3.3.0/app/Mage.php
113
113
  - fixtures/magento_1.4.0.0/app/Mage.php
114
114
  - fixtures/magento_1.7.0.2/app/Mage.php
115
+ - fixtures/magento_1.7.0.2/app/code/core/Mage/Catalog/etc/config.xml
116
+ - fixtures/magento_1.7.0.2/app/code/core/Mage/Sales/etc/config.xml
115
117
  - fixtures/magento_root/app/code/core/Mage/A/etc/config.xml
116
118
  - fixtures/magento_root/app/code/core/Mage/B/etc/config.xml
117
119
  - fixtures/magento_root/app/code/core/Mage/C/etc/config.xml
@@ -125,6 +127,8 @@ files:
125
127
  - lib/maruto/magento_instance.rb
126
128
  - lib/maruto/magento_version.rb
127
129
  - lib/maruto/module_configuration.rb
130
+ - lib/maruto/module_configuration/event_observers.rb
131
+ - lib/maruto/module_configuration/models.rb
128
132
  - lib/maruto/module_definition.rb
129
133
  - lib/maruto/runner.rb
130
134
  - lib/maruto/version.rb
@@ -132,6 +136,7 @@ files:
132
136
  - spec/magento_version_spec.rb
133
137
  - spec/module_definition_spec.rb
134
138
  - spec/module_events_spec.rb
139
+ - spec/module_models_spec.rb
135
140
  - spec/module_version_spec.rb
136
141
  - spec/spec_helper.rb
137
142
  homepage: https://github.com/jlgeering/maruto
@@ -163,5 +168,6 @@ test_files:
163
168
  - spec/magento_version_spec.rb
164
169
  - spec/module_definition_spec.rb
165
170
  - spec/module_events_spec.rb
171
+ - spec/module_models_spec.rb
166
172
  - spec/module_version_spec.rb
167
173
  - spec/spec_helper.rb