Class: Detroit::Syntax

Inherits:
Tool
  • Object
show all
Defined in:
lib/detroit-syntax.rb

Overview

The Syntax tool simply checks all Ruby code for syntax errors. It is a rather trivial tool, and is here mainly for example sake.

NOTE: This method shells out to the command line using ‘ruby -c`.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#excludeObject

Globs to exclude.



23
24
25
# File 'lib/detroit-syntax.rb', line 23

def exclude
  @exclude
end

#extraObject

Extra options to append to ‘ruby -c` command.



29
30
31
# File 'lib/detroit-syntax.rb', line 29

def extra
  @extra
end

#filesObject

Files to check.



17
18
19
# File 'lib/detroit-syntax.rb', line 17

def files
  @files
end

#ignoreObject

Files to ignore based on file name patterns.



26
27
28
# File 'lib/detroit-syntax.rb', line 26

def ignore
  @ignore
end

#loadpathObject

Add these folders to the $LOAD_PATH.



20
21
22
# File 'lib/detroit-syntax.rb', line 20

def loadpath
  @loadpath
end

Class Method Details

.man_pageObject



177
178
179
# File 'lib/detroit-syntax.rb', line 177

def self.man_page
  File.dirname(__FILE__)+'/../man/detroit-syntax.5'
end

Instance Method Details

#assemble(station, options = {}) ⇒ Object

Attach check method to test station.



53
54
55
56
57
58
# File 'lib/detroit-syntax.rb', line 53

def assemble(station, options={})
  case station
  when :test
    check
  end
end

#assemble?(station, options = {}) ⇒ Boolean

Attaches check method to test station.

Returns:

  • (Boolean)


45
46
47
48
49
50
# File 'lib/detroit-syntax.rb', line 45

def assemble?(station, options={})
  case station
  when :test
    true
  end
end

#checkObject

Verify syntax of ruby scripts.



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/detroit-syntax.rb', line 74

def check
  list = run_syntax_check

  if log && (logfile.outofdate?(*files) or force?)
    log_syntax_errors(list)
  end

  abort "Syntax errors found." if list.size > 0

  return true
end

#logObject

Log syntax errors?



37
38
39
# File 'lib/detroit-syntax.rb', line 37

def log
  @log
end

#log=(file_or_bool) ⇒ Object

File name of log file or true to use default ‘log/syntax.rdoc` file.



32
33
34
# File 'lib/detroit-syntax.rb', line 32

def log=(file_or_bool)
  @log = file_or_bool
end

#logfileObject

If log is given save results to this log file.



64
65
66
67
68
69
70
71
# File 'lib/detroit-syntax.rb', line 64

def logfile
  case log
  when String
    Pathname.new(log)
  else
    project.log + 'syntax.rdoc'
  end
end