Class: Codeqa::Checkers::CheckErb

Inherits:
Codeqa::Checker show all
Defined in:
lib/codeqa/checkers/check_erb.rb

Instance Attribute Summary

Attributes inherited from Codeqa::Checker

#errors, #sourcefile

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Codeqa::Checker

#initialize

Constructor Details

This class inherits a constructor from Codeqa::Checker

Class Method Details

.available?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/codeqa/checkers/check_erb.rb', line 8

def self.available?
  engine?
end

.check?(sourcefile) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
# File 'lib/codeqa/checkers/check_erb.rb', line 4

def self.check?(sourcefile)
  sourcefile.erb?
end

.engine?Boolean

rubocop:enable RescueException,HandleExceptions

Returns:

  • (Boolean)


37
38
39
40
41
42
43
44
45
# File 'lib/codeqa/checkers/check_erb.rb', line 37

def self.engine?
  @@engine ||= if %w(actionview action_view).include? Codeqa.configuration.erb_engine.downcase
                 require 'action_view'
                 true
               else
                 require 'erb'
                 true
               end
end

Instance Method Details

#checkObject

rubocop:disable RescueException,HandleExceptions



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/codeqa/checkers/check_erb.rb', line 21

def check
  if defined?(ActionView)
    ActionView::Template::Handlers::Erubis.new(erb).result
  else
    ERB.new(sourcefile.content.gsub('<%=', '<%'), nil, '-').result
  end
rescue SyntaxError => e
  errors.add(nil, <<-EOF)
  #{e.message}
  #{e.backtrace.join("\n")}
  EOF
rescue Exception
  true # valid syntax - just the proper setup for the template/rendering is missing
end

#hintObject



16
17
18
# File 'lib/codeqa/checkers/check_erb.rb', line 16

def hint
  'There is a syntax error in the ruby code of the erb parsed file.'
end

#nameObject



12
13
14
# File 'lib/codeqa/checkers/check_erb.rb', line 12

def name
  'erb syntax'
end