Class: Greener::Checker::Base
- Inherits:
-
Object
- Object
- Greener::Checker::Base
- Defined in:
- lib/greener/checker/base.rb
Overview
Base checker class
Direct Known Subclasses
Instance Attribute Summary collapse
-
#violations ⇒ Object
readonly
Returns the value of attribute violations.
Instance Method Summary collapse
-
#feature ⇒ Object
For readability in checker subclasses.
-
#initialize(ast, path, config) ⇒ Base
constructor
A new instance of Base.
-
#log_violation(line, col, msg = nil, raw_txt = nil) ⇒ Object
Adds violation data to the @violations array.
-
#message ⇒ Object
Read the violation message text set in the checker subclass.
-
#raw_line(num) ⇒ Object
Given a num, returns the full text corresponding to that line number in the file.
-
#run ⇒ Object
Method invoked when a checker is applied to a file.
Constructor Details
#initialize(ast, path, config) ⇒ Base
Returns a new instance of Base.
7 8 9 10 11 12 13 |
# File 'lib/greener/checker/base.rb', line 7 def initialize(ast, path, config) @ast = ast @path = path @config = config @violations = [] end |
Instance Attribute Details
#violations ⇒ Object (readonly)
Returns the value of attribute violations.
5 6 7 |
# File 'lib/greener/checker/base.rb', line 5 def violations @violations end |
Instance Method Details
#feature ⇒ Object
For readability in checker subclasses
41 42 43 |
# File 'lib/greener/checker/base.rb', line 41 def feature @ast end |
#log_violation(line, col, msg = nil, raw_txt = nil) ⇒ Object
Adds violation data to the @violations array
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/greener/checker/base.rb', line 25 def log_violation(line, col, msg = nil, raw_txt = nil) # Set defaults for last 2 params if not overridden raw_txt ||= raw_line(line) msg ||= violation = {} violation[:file] = @path violation[:line] = line violation[:column] = col violation[:text_of_line] = raw_txt violation[:message] = msg @violations << violation end |
#message ⇒ Object
Read the violation message text set in the checker subclass
20 21 22 |
# File 'lib/greener/checker/base.rb', line 20 def self.class::MSG end |
#raw_line(num) ⇒ Object
Given a num, returns the full text corresponding to that line number in the file
46 47 48 |
# File 'lib/greener/checker/base.rb', line 46 def raw_line(num) open(@path).each_line.take(num).last end |
#run ⇒ Object
Method invoked when a checker is applied to a file
16 17 |
# File 'lib/greener/checker/base.rb', line 16 def run end |