Class: Tailor::Rulers::AllowInvalidRubyRuler

Inherits:
Tailor::Ruler show all
Defined in:
lib/tailor/rulers/allow_invalid_ruby_ruler.rb

Instance Attribute Summary

Attributes inherited from Tailor::Ruler

#lexer_observers

Instance Method Summary collapse

Methods inherited from Tailor::Ruler

#add_child_ruler, #problem_type, #problems

Methods included from Logger::Mixin

included

Constructor Details

#initialize(config, options) ⇒ AllowInvalidRubyRuler

Returns a new instance of AllowInvalidRubyRuler.



7
8
9
10
# File 'lib/tailor/rulers/allow_invalid_ruby_ruler.rb', line 7

def initialize(config, options)
  super(config, options)
  add_lexer_observers :file_beg
end

Instance Method Details

#file_beg_update(file_name) ⇒ Object



12
13
14
15
# File 'lib/tailor/rulers/allow_invalid_ruby_ruler.rb', line 12

def file_beg_update(file_name)
  @file_name = file_name
  measure
end

#invalid_ruby?Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
# File 'lib/tailor/rulers/allow_invalid_ruby_ruler.rb', line 18

def invalid_ruby?
  log 'Checking for valid Ruby...'
  result = `"#{Gem.ruby}" -c "#{@file_name}"`

  result.size.zero?
end

#measureObject



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/tailor/rulers/allow_invalid_ruby_ruler.rb', line 25

def measure
  if invalid_ruby? && @config == false
    lineno = 0
    column = 0
    msg = 'File contains invalid Ruby; run `ruby -c [your_file.rb]` '
    msg << 'for more details.'

    @problems << Problem.new(problem_type, lineno, column, msg,
      @options[:level])
  end
end