Class: Roodi::Core::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/roodi/core/runner.rb

Constant Summary collapse

DEFAULT_CONFIG =
File.join(File.dirname(__FILE__), "..", "..", "..", "roodi.yml")

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*checks) ⇒ Runner

Returns a new instance of Runner.



15
16
17
18
19
# File 'lib/roodi/core/runner.rb', line 15

def initialize(*checks)
  @config = DEFAULT_CONFIG
  @checks = checks unless checks.empty?
  @parser = Parser.new
end

Instance Attribute Details

#config=(value) ⇒ Object (writeonly)

Sets the attribute config

Parameters:

  • value

    the value to set the attribute config to.



13
14
15
# File 'lib/roodi/core/runner.rb', line 13

def config=(value)
  @config = value
end

Instance Method Details

#check(filename, content) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/roodi/core/runner.rb', line 21

def check(filename, content)
  @checks ||= load_checks
  @checker ||= CheckingVisitor.new(@checks)
  @checks.each {|check| check.start_file(filename)}
  node = parse(filename, content)
  node.accept(@checker) if node
  @checks.each {|check| check.end_file(filename)}
end

#check_content(content, filename = "dummy-file.rb") ⇒ Object



30
31
32
# File 'lib/roodi/core/runner.rb', line 30

def check_content(content, filename = "dummy-file.rb")
  check(filename, content)
end

#check_file(filename) ⇒ Object



34
35
36
# File 'lib/roodi/core/runner.rb', line 34

def check_file(filename)
  check(filename, File.read(filename))
end

#errorsObject



52
53
54
55
56
# File 'lib/roodi/core/runner.rb', line 52

def errors
  @checks ||= []
  all_errors = @checks.collect {|check| check.errors}
  all_errors.flatten
end


38
39
40
41
42
# File 'lib/roodi/core/runner.rb', line 38

def print(filename, content)
  node = @parser.parse(content, filename)
  puts "Line: #{node.line}"
  pp node
end


44
45
46
# File 'lib/roodi/core/runner.rb', line 44

def print_content(content)
  print("dummy-file.rb", content)
end


48
49
50
# File 'lib/roodi/core/runner.rb', line 48

def print_file(filename)
  print(filename, File.read(filename))
end