maruto 0.0.2 → 0.0.3
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.
- data/README.md +1 -1
- data/lib/maruto/magento_config.rb +102 -6
- data/lib/maruto/runner.rb +46 -15
- data/lib/maruto/version.rb +1 -1
- metadata +2 -2
data/README.md
CHANGED
|
@@ -7,7 +7,10 @@ module Maruto
|
|
|
7
7
|
def initialize(magento_root)
|
|
8
8
|
|
|
9
9
|
@modules = {}
|
|
10
|
+
|
|
11
|
+
@global_model_groups = {}
|
|
10
12
|
@global_events_observers = {}
|
|
13
|
+
|
|
11
14
|
@warnings = []
|
|
12
15
|
|
|
13
16
|
Dir.chdir(magento_root) do
|
|
@@ -49,6 +52,32 @@ module Maruto
|
|
|
49
52
|
|
|
50
53
|
mm_config[:version] = doc.at_xpath("/config/modules/#{mm_name}/version").content if doc.at_xpath("/config/modules/#{mm_name}/version")
|
|
51
54
|
|
|
55
|
+
##########################################################################################
|
|
56
|
+
# MODELS
|
|
57
|
+
|
|
58
|
+
doc.xpath('/config/global/models/*').each do |node|
|
|
59
|
+
load_model(mm_name, node)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
if mm_name.start_with? "Mage_" then
|
|
63
|
+
# special case for Mage_NAME modules: if not defined, fallback to Mage_Model_NAME
|
|
64
|
+
group_name = mm_name.sub("Mage_", "").downcase
|
|
65
|
+
if !@global_model_groups.include? group_name then
|
|
66
|
+
@global_model_groups[group_name] = {
|
|
67
|
+
:class => "#{mm_name}_Model",
|
|
68
|
+
:defined => :fallback,
|
|
69
|
+
}
|
|
70
|
+
end
|
|
71
|
+
if !@global_model_groups[group_name][:class] then
|
|
72
|
+
# TODO warn? => missing dep?
|
|
73
|
+
@global_model_groups[group_name][:class] = "#{mm_name}_Model"
|
|
74
|
+
@global_model_groups[group_name][:defined] = :fallback
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
##########################################################################################
|
|
79
|
+
# EVENTS
|
|
80
|
+
|
|
52
81
|
# TODO same for:
|
|
53
82
|
# '/config/frontend/events/*'
|
|
54
83
|
# '/config/adminhtml/events/*'
|
|
@@ -57,8 +86,6 @@ module Maruto
|
|
|
57
86
|
event = node.name
|
|
58
87
|
observers = @global_events_observers[event] ||= {}
|
|
59
88
|
|
|
60
|
-
# puts node if mm_name == 'Enterprise_Reminder'
|
|
61
|
-
|
|
62
89
|
node.xpath("observers/*").each do |observer_node|
|
|
63
90
|
observer_name = observer_node.name
|
|
64
91
|
if observers.include? observer_name
|
|
@@ -70,8 +97,8 @@ module Maruto
|
|
|
70
97
|
# print_module(mod_second)
|
|
71
98
|
end
|
|
72
99
|
observers[observer_name] = {
|
|
73
|
-
:class
|
|
74
|
-
:method
|
|
100
|
+
:class => observer_node.at_xpath('class').content,
|
|
101
|
+
:method => observer_node.at_xpath('method').content,
|
|
75
102
|
:defined => mm_name,
|
|
76
103
|
}
|
|
77
104
|
end
|
|
@@ -80,16 +107,28 @@ module Maruto
|
|
|
80
107
|
end
|
|
81
108
|
|
|
82
109
|
end
|
|
110
|
+
end # modules().each
|
|
111
|
+
|
|
112
|
+
# check if all model_groups have a class attribute
|
|
113
|
+
# TODO write test
|
|
114
|
+
@global_model_groups.each do |group_name, model_group|
|
|
115
|
+
if !model_group[:class] && !group_name.end_with?('_mysql4') then
|
|
116
|
+
@warnings << "module:#{model_group[:define]} model_group:#{group_name} - missing class attribute for model"
|
|
117
|
+
end
|
|
83
118
|
end
|
|
84
119
|
|
|
85
|
-
end
|
|
120
|
+
end # Dir.chdir(magento_root)
|
|
86
121
|
end
|
|
87
122
|
|
|
88
123
|
def modules()
|
|
89
124
|
Hash[tsort.map { |name| [name, @modules[name]] }]
|
|
90
125
|
end
|
|
91
126
|
|
|
92
|
-
def
|
|
127
|
+
def models()
|
|
128
|
+
@global_model_groups
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def observers()
|
|
93
132
|
@global_events_observers
|
|
94
133
|
end
|
|
95
134
|
|
|
@@ -130,5 +169,62 @@ module Maruto
|
|
|
130
169
|
@modules[name] = config
|
|
131
170
|
end
|
|
132
171
|
|
|
172
|
+
def load_model(module_name, xml_node)
|
|
173
|
+
group_name = xml_node.name
|
|
174
|
+
|
|
175
|
+
# this xml_node declares a new model
|
|
176
|
+
load_model_definition(module_name, group_name, xml_node) if xml_node.at_xpath('class')
|
|
177
|
+
|
|
178
|
+
# this xml_node declares a model rewrite
|
|
179
|
+
load_model_rewrite(module_name, group_name, xml_node) if xml_node.at_xpath('rewrite')
|
|
180
|
+
|
|
181
|
+
if !xml_node.at_xpath('class') && !xml_node.at_xpath('rewrite') && !xml_node.at_xpath('entities')
|
|
182
|
+
@warnings << "module:#{module_name} model_group:#{group_name} - unrecognized model"
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
def load_model_definition(module_name, group_name, xml_node)
|
|
188
|
+
# check for redefinition
|
|
189
|
+
if @global_model_groups.include?(group_name) && @global_model_groups[group_name][:class] then
|
|
190
|
+
mod_first = @global_model_groups[group_name][:defined]
|
|
191
|
+
mod_second = module_name
|
|
192
|
+
@warnings << "model_group:#{group_name} - defined in #{mod_first} and redefined in #{mod_second}"
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
# model_group hash could alread have been created (rewrites for this model in another module)
|
|
196
|
+
model_group = @global_model_groups[group_name] ||= {}
|
|
197
|
+
|
|
198
|
+
model_group[:class] = xml_node.at_xpath('class').content
|
|
199
|
+
model_group[:defined] = module_name
|
|
200
|
+
# optional
|
|
201
|
+
model_group[:resource_model] = xml_node.at_xpath('resourceModel').content if xml_node.at_xpath('resourceModel')
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
def load_model_rewrite(module_name, group_name, xml_node)
|
|
205
|
+
# check if model_group already defined, else warn missing dependency relation
|
|
206
|
+
# TODO is this an issue or is this allowed?
|
|
207
|
+
# if !@global_model_groups.include? group_name then
|
|
208
|
+
# @warnings << "module:#{module_name} - rewrites model_group:#{group_name} which isn't defined yet (missing dependency?)"
|
|
209
|
+
# end
|
|
210
|
+
|
|
211
|
+
# model_group and model_group[:rewrites] hashes could alread have been created
|
|
212
|
+
model_group = @global_model_groups[group_name] ||= {}
|
|
213
|
+
rewrites = model_group[:rewrites] ||= {}
|
|
214
|
+
|
|
215
|
+
xml_node.xpath("rewrite/*").each do |rewrite_node|
|
|
216
|
+
rewrite_name = rewrite_node.name
|
|
217
|
+
if rewrites.include? rewrite_name
|
|
218
|
+
# TODO check if there is a dependency path between mod_first and mod_second?
|
|
219
|
+
mod_first = rewrites[rewrite_name][:defined]
|
|
220
|
+
mod_second = module_name
|
|
221
|
+
@warnings << "model_group:#{group_name} rewrite:#{rewrite_name} - defined in #{mod_first} and redefined in #{mod_second}"
|
|
222
|
+
end
|
|
223
|
+
rewrites[rewrite_name] = {
|
|
224
|
+
:class => rewrite_node.content,
|
|
225
|
+
:defined => module_name,
|
|
226
|
+
}
|
|
227
|
+
end
|
|
228
|
+
end
|
|
133
229
|
end
|
|
134
230
|
end
|
data/lib/maruto/runner.rb
CHANGED
|
@@ -6,17 +6,18 @@ require 'thor'
|
|
|
6
6
|
class Maruto::Runner < Thor
|
|
7
7
|
include Thor::Actions
|
|
8
8
|
|
|
9
|
-
desc "magento?
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
check_magento_folder(
|
|
9
|
+
desc "magento?", "check if MAGENTO_ROOT contains a magento app"
|
|
10
|
+
method_option :magento_root, :aliases => "-m", :default => "."
|
|
11
|
+
def magento?()
|
|
12
|
+
check_magento_folder()
|
|
13
|
+
puts "OK"
|
|
13
14
|
end
|
|
14
15
|
|
|
15
|
-
desc "lint
|
|
16
|
-
|
|
16
|
+
desc "lint", "lint php files in MAGENTO_ROOT/app/code"
|
|
17
|
+
method_option :magento_root, :aliases => "-m", :default => "."
|
|
18
|
+
def lint()
|
|
17
19
|
|
|
18
|
-
magento_root =
|
|
19
|
-
check_magento_folder(magento_root)
|
|
20
|
+
magento_root = check_magento_folder()
|
|
20
21
|
|
|
21
22
|
# TODO move this into a lint_php method
|
|
22
23
|
inside(magento_root) do
|
|
@@ -33,15 +34,41 @@ class Maruto::Runner < Thor
|
|
|
33
34
|
end
|
|
34
35
|
end
|
|
35
36
|
|
|
36
|
-
desc "
|
|
37
|
-
|
|
37
|
+
desc "warnings", "list potential problems found in the config"
|
|
38
|
+
method_option :magento_root, :aliases => "-m", :default => "."
|
|
39
|
+
def warnings()
|
|
38
40
|
|
|
39
|
-
magento_root =
|
|
40
|
-
check_magento_folder(magento_root)
|
|
41
|
+
magento_root = check_magento_folder()
|
|
41
42
|
|
|
42
43
|
magento_config = Maruto::MagentoConfig.new magento_root
|
|
44
|
+
magento_config.print_warnings
|
|
43
45
|
|
|
44
|
-
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
desc "models", "list models sorted and grouped by their group_name"
|
|
49
|
+
method_option :magento_root, :aliases => "-m", :default => "."
|
|
50
|
+
def models()
|
|
51
|
+
|
|
52
|
+
magento_root = check_magento_folder()
|
|
53
|
+
|
|
54
|
+
magento_config = Maruto::MagentoConfig.new magento_root
|
|
55
|
+
|
|
56
|
+
magento_config.models.sort_by { |k, v| k }.each do |name,group|
|
|
57
|
+
puts "#{name} #{group}"
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
desc "observers", "list observers sorted and grouped by their events"
|
|
64
|
+
method_option :magento_root, :aliases => "-m", :default => "."
|
|
65
|
+
def observers()
|
|
66
|
+
|
|
67
|
+
magento_root = check_magento_folder()
|
|
68
|
+
|
|
69
|
+
magento_config = Maruto::MagentoConfig.new magento_root
|
|
70
|
+
|
|
71
|
+
magento_config.observers.sort_by { |k, v| k }.each do |event, observers|
|
|
45
72
|
puts event
|
|
46
73
|
observers.each do |observer|
|
|
47
74
|
puts " #{observer}"
|
|
@@ -51,7 +78,9 @@ class Maruto::Runner < Thor
|
|
|
51
78
|
end
|
|
52
79
|
|
|
53
80
|
no_commands do
|
|
54
|
-
def check_magento_folder(
|
|
81
|
+
def check_magento_folder()
|
|
82
|
+
magento_root = Pathname.new(options[:magento_root]).cleanpath
|
|
83
|
+
|
|
55
84
|
raise Thor::Error, "not a folder: #{magento_root}" unless magento_root.directory?
|
|
56
85
|
|
|
57
86
|
is_magento = (magento_root + 'app').directory? &&
|
|
@@ -59,7 +88,9 @@ class Maruto::Runner < Thor
|
|
|
59
88
|
(magento_root + 'app/etc').directory? &&
|
|
60
89
|
(magento_root + 'app/etc/modules').directory? &&
|
|
61
90
|
(magento_root + 'app/etc/local.xml').file?
|
|
62
|
-
raise Thor::Error, "could not find magento in this folder: #{magento_root}" unless is_magento
|
|
91
|
+
raise Thor::Error, "could not find magento in this folder: #{magento_root.realpath}#{options[:magento_root] == '.' ? ' (try -m MAGENTO_ROOT)' : ''}" unless is_magento
|
|
92
|
+
|
|
93
|
+
return magento_root
|
|
63
94
|
end
|
|
64
95
|
end
|
|
65
96
|
end
|
data/lib/maruto/version.rb
CHANGED
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.
|
|
4
|
+
version: 0.0.3
|
|
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-
|
|
12
|
+
date: 2013-04-01 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: nokogiri
|