Class: Maruto::Runner

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/maruto/runner.rb

Instance Method Summary collapse

Instance Method Details

#lintObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/maruto/runner.rb', line 33

def lint()

	magento_root = check_magento_folder()

	# TODO move this into a lint_php method
	inside(magento_root) do
		Dir.glob( 'app/code/**/*.php' ) do |file|
			begin
				firstline = File.open(file, &:readline)
				# TODO return list of warnings
				# TODO case insensitive
				puts file unless firstline.start_with?("<?php") or firstline.start_with?("<?PHP")
			rescue
				# TODO return list of errors
				puts "error in " + file
			end
		end
	end
end

#magento?Boolean

Returns:

  • (Boolean)


26
27
28
29
# File 'lib/maruto/runner.rb', line 26

def magento?()
	check_magento_folder()
	puts "OK"
end

#modelsObject



89
90
91
92
93
94
95
96
97
98
99
# File 'lib/maruto/runner.rb', line 89

def models()

	magento_root = check_magento_folder()

	magento_config = Maruto::MagentoConfig.new magento_root

	magento_config.models.sort_by { |k, v| k }.each do |name,group|
		puts "#{name} #{group}"
	end

end

#modulesObject



103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/maruto/runner.rb', line 103

def modules()

	magento_root = check_magento_folder()

	magento = Maruto::MagentoInstance.load(magento_root)

	magento[:all_modules].each do |name, m|
		deps = ''
		deps = ", dependencies:[#{m[:dependencies].collect{ |d| d.to_s }.join(', ')}]" if m[:dependencies]
		puts "#{name}(active:#{m[:active]}, code_pool:#{m[:code_pool]}, defined:#{m[:defined]}#{deps})"
	end

end

#observers(filter = nil) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/maruto/runner.rb', line 120

def observers(filter = nil)

	magento_root = check_magento_folder()

	magento = Maruto::MagentoInstance.load(magento_root)

	group_by_scope = options[:group_by_scope]

	if group_by_scope then
		magento[:event_observers].each do |area, events|
			events.each do |event, observers|
				if filter.nil? or event.include? filter
					puts "#{area}/#{event}"
					observers.each do |name, observer|
						puts "  #{name} (module:#{observer[:module]} type:#{observer[:type]} class:#{observer[:class]} method:#{observer[:method]})"
					end
				end
			end
		end
	else
		grouped_by_events = Hash.new
		magento[:event_observers].each do |area, events|
			events.each do |event, observers|
				grouped_by_events[event] ||= Hash.new
				grouped_by_events[event][area] = observers
			end
		end
		grouped_by_events.sort_by { |k, v| k }.each do |event, areas|
			if filter.nil? or event.include? filter
				puts "#{event}"
				areas.each do |area, observers|
					observers.each do |name, observer|
						puts "  #{area}/#{name} (module:#{observer[:module]} type:#{observer[:type]} class:#{observer[:class]} method:#{observer[:method]})"
					end
				end
			end
		end
	end

end

#versionObject



13
14
15
16
17
18
19
20
21
22
# File 'lib/maruto/runner.rb', line 13

def version
	say "Maruto #{Maruto::VERSION}"
	begin
		magento_root = check_magento_folder()
		magento = Maruto::MagentoInstance.load(magento_root)
		say "Magento #{magento[:version].join('.')}"
	rescue Thor::Error
		# do nothing
	end
end

#warningsObject



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
# File 'lib/maruto/runner.rb', line 56

def warnings()

	magento_root = check_magento_folder()

	magento_config = Maruto::MagentoConfig.new magento_root
	magento_config.print_warnings

	# next gen maruto:

	with_core = options[:with_core]

	magento = Maruto::MagentoInstance.load(magento_root)

	magento[:warnings].group_by { |e| e[:module] }.each do |m,module_warnings|
		if with_core or magento[:all_modules][m][:code_pool] != :core then
			puts "[module:#{m}]"
			module_warnings.group_by { |e| e[:file] }.each do |file,warnings|
				puts "  [file:#{file}]"
				warnings.each do |w|
					puts "    #{w[:message]}"
				end
			end
		end
	end

	if magento[:warnings].empty?
		exit 0
	end
	exit 1
end