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.
Constant Summary collapse
- DEFAULT_CHECKS_CONFIG =
{ :AbcMetricMethodCheck => {}, :AssignmentInConditionalCheck => {}, :CaseMissingElseCheck => {}, :ClassLineCountCheck => {}, :ClassNameCheck => {}, :ControlCouplingCheck => {}, :CyclomaticComplexityBlockCheck => {}, :CyclomaticComplexityMethodCheck => {}, :EmptyRescueBodyCheck => {}, :FlogBlockCheck => {}, :FlogClassCheck => {}, :FlogMethodCheck => {}, :ForLoopCheck => {}, :GlobalVariableCheck => {}, :MethodLineCountCheck => {}, :MethodNameCheck => {}, :ModuleLineCountCheck => {}, :ModuleNameCheck => {}, :ParameterNumberCheck => {}, :ClassVariableCheck => {}, :'Rails::AttrProtectedCheck' => {}, :'Rails::AttrAccessibleCheck' => {}, :'Rails::InstanceVarInPartialCheck' => {}, :'Rails::ValidationsCheck' => {}, :'Rails::ParamsHashInViewCheck' => {}, :'Rails::SessionHashInViewCheck' => {}, :'Rails::CustomInitializeMethodCheck' => {} }
Instance Attribute Summary collapse
-
#checks ⇒ Object
readonly
Returns the value of attribute checks.
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, ignore_paths = []) ⇒ Object
Processes the passed
paths. -
#initialize(checks_config = {}) ⇒ Runner
constructor
Initializes a Runner.
-
#warnings ⇒ Object
Gets the warnings that were produced by the checks.
Constructor Details
#initialize(checks_config = {}) ⇒ Runner
Initializes a Runner
Parameters
- checks_config - The check configuration to use; You can either specify an array of specs to use like this [:ClassLineCountCheck => { :threshold => 10 }] or you can specify a hash that will then be merged with the default configuration: { :ClassNameCheck => { pattern: 'test' }, :ClassLineCountCheck => { :threshold => 10 } } You can enable/disable a check by setting the value of the hash to sth. truthy/falsy: { :ClassNameCheck => false, :AbcMetricMethodCheck => {} }
56 57 58 59 |
# File 'lib/simplabs/excellent/runner.rb', line 56 def initialize(checks_config = {}) @checks = load_checks(checks_config) @parser = Parsing::Parser.new end |
Instance Attribute Details
#checks ⇒ Object (readonly)
Returns the value of attribute checks.
44 45 46 |
# File 'lib/simplabs/excellent/runner.rb', line 44 def checks @checks 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).
67 68 69 70 71 |
# File 'lib/simplabs/excellent/runner.rb', line 67 def check(filename, code) @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).
78 79 80 |
# File 'lib/simplabs/excellent/runner.rb', line 78 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.
87 88 89 |
# File 'lib/simplabs/excellent/runner.rb', line 87 def check_file(filename) check(filename, File.read(filename)) end |
#check_paths(paths, formatter = nil, ignore_paths = []) ⇒ 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, its
start,file,warningandendmethods will be called - ignore_paths - The paths to ignore
98 99 100 101 102 103 104 105 |
# File 'lib/simplabs/excellent/runner.rb', line 98 def check_paths(paths, formatter = nil, ignore_paths = []) formatter.start if formatter collect_files(paths, ignore_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.
108 109 110 |
# File 'lib/simplabs/excellent/runner.rb', line 108 def warnings @checks.collect { |check| check.warnings }.flatten end |