Class: ExecutableFilesCheckAction
Instance Method Summary
collapse
#count_loc
Methods inherited from BuildAction
command_line_action_name, command_line_action_names, create_action_from_command_line_name, detailed_template_file, #score, summary_template_file
#get_implementors
Constructor Details
Returns a new instance of ExecutableFilesCheckAction.
48
49
50
51
|
# File 'lib/kwala/actions/executable_files_check.rb', line 48
def initialize
@problem_files = Array.new
@shellbang_files_LOC = Hash.new
end
|
Instance Method Details
#build_action(context) ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/kwala/actions/executable_files_check.rb', line 53
def build_action(context)
context.ruby_files.each do |f|
exec = File.executable?(f)
bang = ("#!/" == IO.read(f, 3, 0))
if exec ^ bang
if exec
prob = "executable, no shell bang"
else
prob = "shell bang, not executable"
end
@problem_files << { :filename => f, :problem => prob }
end
@shellbang_files_LOC[f] = count_loc(f) if bang
end
@sorted_shellbang_files_LOC = @shellbang_files_LOC.sort {|a,b| b[1] <=> a[1] }
end
|
#detailed_display(context) ⇒ Object
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/kwala/actions/executable_files_check.rb', line 92
def detailed_display(context)
template = TemplateFile.new(self.class.detailed_template_file)
res = {}
if @problem_files.size > 0
res[:problem_files] = { :files => @problem_files }
end
res[:files] = @sorted_shellbang_files_LOC.map do |f, l|
{ :filename => f, :lines_of_code => l }
end
context.amrita_data[:executable_files_check_results] = res
det_res = ProjectBuilderUtils.expand_template(template, context.amrita_data)
det_file = "#{context.output_directory}/#{context.project_name}_executable_files_check.html"
[det_file, det_res]
end
|
#summary_display(context) ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/kwala/actions/executable_files_check.rb', line 70
def summary_display(context)
template = TemplateFile.new(self.class.summary_template_file)
res = {}
if @problem_files.size > 0
res[:problem_files] = { :files => @problem_files }
end
top_ten_files = @sorted_shellbang_files_LOC[0..9]
res[:files] = top_ten_files.map do |f, l|
{ :filename => f, :lines_of_code => l }
end
context.amrita_data[:executable_files_check_results] = res
execfilecodesize_base = "#{context.project_name}_executable_files_check.html"
context.amrita_data[:executable_files_check_details] =
(Amrita::e(:a, :href => execfilecodesize_base) { "Executable Files Check Details" } )
summary_expand(template, context)
end
|