Class: Rubycritic::FileGenerator
Constant Summary
collapse
- LINE_NUMBER_OFFSET =
1
- FILE_TEMPLATE =
ERB.new(File.read(File.join(TEMPLATES_DIR, "file.html.erb")))
- LAYOUT_TEMPLATE =
ERB.new(File.read(File.join(TEMPLATES_DIR, "layouts", "application.html.erb")))
BaseGenerator::REPORT_DIR, BaseGenerator::TEMPLATES_DIR
Instance Method Summary
collapse
#file_pathname, #get_binding, #index_path, #stylesheet_path
Constructor Details
#initialize(pathname, smells) ⇒ FileGenerator
Returns a new instance of FileGenerator.
12
13
14
15
|
# File 'lib/rubycritic/report_generators/file_generator.rb', line 12
def initialize(pathname, smells)
@pathname = pathname
@smells = smells
end
|
Instance Method Details
#analysed_file_name ⇒ Object
25
26
27
|
# File 'lib/rubycritic/report_generators/file_generator.rb', line 25
def analysed_file_name
@pathname.basename.sub_ext('').to_s
end
|
#file_directory ⇒ Object
17
18
19
|
# File 'lib/rubycritic/report_generators/file_generator.rb', line 17
def file_directory
File.join(REPORT_DIR, File.dirname(@pathname))
end
|
#file_name ⇒ Object
21
22
23
|
# File 'lib/rubycritic/report_generators/file_generator.rb', line 21
def file_name
"#{analysed_file_name}.html"
end
|
#render ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/rubycritic/report_generators/file_generator.rb', line 29
def render
file_code = ""
File.readlines(@pathname).each.with_index(LINE_NUMBER_OFFSET) do |line_text, line_number|
location = Location.new(@pathname, line_number)
line_smells = @smells.select { |smell| smell.located_in?(location) }
file_code << LineGenerator.new(line_text, line_number, line_smells).render
end
file_body = FILE_TEMPLATE.result(self.get_binding { file_code })
LAYOUT_TEMPLATE.result(self.get_binding { file_body })
end
|