Class: MountainBerryFields::Test::RubySyntaxChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/mountain_berry_fields/test.rb

Overview

checks syntax of a code example

Instance Method Summary collapse

Constructor Details

#initialize(code_to_test) ⇒ RubySyntaxChecker

Returns a new instance of RubySyntaxChecker.


68
69
70
# File 'lib/mountain_berry_fields/test.rb', line 68

def initialize(code_to_test)
  @code_to_test = code_to_test
end

Instance Method Details

#invalid_messageObject


79
80
81
82
# File 'lib/mountain_berry_fields/test.rb', line 79

def invalid_message
  valid?
  "#{@stderr.chomp}\n\noriginal file:\n#@code_to_test"
end

#valid?Boolean

Returns:

  • (Boolean)

72
73
74
75
76
77
# File 'lib/mountain_berry_fields/test.rb', line 72

def valid?
  return @valid if defined? @valid
  out, err, status = Open3.capture3 'ruby -c', stdin_data: @code_to_test
  @stderr = err
  @valid = status.exitstatus.zero?
end