Class: Simplabs::Excellent::Runner
- Inherits:
-
Object
- Object
- Simplabs::Excellent::Runner
- Defined in:
- lib/simplabs/excellent/runner.rb
Overview
The Runner is the interface to invoke parsing and processing of source code. You can pass either a String containing the code to process or the name of a file to read the code to process from.
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_CONFIG =
{ :AssignmentInConditionalCheck => { }, :CaseMissingElseCheck => { }, :ClassLineCountCheck => { :threshold => 300 }, :ClassNameCheck => { :pattern => /^[A-Z][a-zA-Z0-9]*$/ }, :SingletonVariableCheck => { }, :GlobalVariableCheck => { }, :CyclomaticComplexityBlockCheck => { :complexity => 4 }, :CyclomaticComplexityMethodCheck => { :complexity => 8 }, :EmptyRescueBodyCheck => { }, :ForLoopCheck => { }, :MethodLineCountCheck => { :line_count => 20 }, :MethodNameCheck => { :pattern => /^[_a-z<>=\[|+-\/\*`]+[_a-z0-9_<>=~@\[\]]*[=!\?]?$/ }, :ModuleLineCountCheck => { :line_count => 300 }, :ModuleNameCheck => { :pattern => /^[A-Z][a-zA-Z0-9]*$/ }, :ParameterNumberCheck => { :parameter_count => 3 }, :FlogMethodCheck => { }, :FlogBlockCheck => { }, :FlogClassCheck => { }, :'Rails::AttrProtectedCheck' => { }, :'Rails::AttrAccessibleCheck' => { }, :'Rails::InstanceVarInPartialCheck' => { }, :'Rails::ValidationsCheck' => { }, :'Rails::ParamsHashInViewCheck' => { }, :'Rails::SessionHashInViewCheck' => { }, :'Rails::CustomInitializeMethodCheck' => { } }
Instance Attribute Summary collapse
-
#config ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#check(filename, code) ⇒ Object
Processes the
codeand sets the file name of the warning tofilename. -
#check_code(code) ⇒ Object
Processes the
code, setting the file name of the warnings to ‘dummy-file.rb’. -
#check_file(filename) ⇒ Object
Processes the file
filename. -
#check_paths(paths, formatter = nil) ⇒ Object
Processes the passed
paths. -
#initialize(*checks) ⇒ Runner
constructor
Initializes a Runner.
-
#warnings ⇒ Object
Gets the warnings that were produced by the checks.
Constructor Details
#initialize(*checks) ⇒ Runner
Initializes a Runner
Parameters
-
checks- The checks to apply - pass instances of the various check classes. If no checks are specified, all checks will be applied.
49 50 51 52 53 |
# File 'lib/simplabs/excellent/runner.rb', line 49 def initialize(*checks) @config = DEFAULT_CONFIG @checks = checks unless checks.empty? @parser = Parsing::Parser.new end |
Instance Attribute Details
#config ⇒ Object
:nodoc:
42 43 44 |
# File 'lib/simplabs/excellent/runner.rb', line 42 def config @config end |
Instance Method Details
#check(filename, code) ⇒ Object
Processes the code and sets the file name of the warning to filename
Parameters
-
filename- The name of the file the code was read from. -
code- The code to process (String).
61 62 63 64 65 66 |
# File 'lib/simplabs/excellent/runner.rb', line 61 def check(filename, code) @checks ||= load_checks @processor ||= Parsing::CodeProcessor.new(@checks) node = parse(filename, code) @processor.process(node) end |
#check_code(code) ⇒ Object
Processes the code, setting the file name of the warnings to ‘dummy-file.rb’
Parameters
-
code- The code to process (String).
73 74 75 |
# File 'lib/simplabs/excellent/runner.rb', line 73 def check_code(code) check('dummy-file.rb', code) end |
#check_file(filename) ⇒ Object
Processes the file filename. The code will be read from the file.
Parameters
-
filename- The name of the file to read the code from.
82 83 84 |
# File 'lib/simplabs/excellent/runner.rb', line 82 def check_file(filename) check(filename, File.read(filename)) end |
#check_paths(paths, formatter = nil) ⇒ Object
Processes the passed paths
Parameters
-
paths- The paths to process (specify file names or directories; will recursively process all ruby files if a directory is given). -
formatter- The formatter to use. If a formatter is specified, itsstart,file,warningandendmethods will be called
92 93 94 95 96 97 98 99 |
# File 'lib/simplabs/excellent/runner.rb', line 92 def check_paths(paths, formatter = nil) formatter.start if formatter collect_files(paths).each do |path| check_file(path) format_file_and_warnings(formatter, path) if formatter end formatter.end if formatter end |
#warnings ⇒ Object
Gets the warnings that were produced by the checks.
102 103 104 105 |
# File 'lib/simplabs/excellent/runner.rb', line 102 def warnings @checks ||= [] @checks.collect { |check| check.warnings }.flatten end |