Class: RailsBestPractices::Core::Runner
- Inherits:
-
Object
- Object
- RailsBestPractices::Core::Runner
- Defined in:
- lib/rails_best_practices/core/runner.rb
Overview
Runner is the main class, it can check source code of a filename with all checks (according to the configuration).
the check process is partitioned into two parts,
-
prepare process, it will do some preparations for further checking, such as remember the model associations.
-
review process, it does real check, if the source code violates some best practices, the violations will be notified.
Class Attribute Summary collapse
-
.base_path ⇒ String
get the base path, by default, the base path is current path.
-
.config_path ⇒ String
get the configuration path, if will default to config/rails_best_practices.yml.
Instance Attribute Summary collapse
-
#checks ⇒ Object
readonly
Returns the value of attribute checks.
Instance Method Summary collapse
- #after_inline_disable ⇒ Object
- #after_lexical ⇒ Object
- #after_prepare ⇒ Object
- #after_review ⇒ Object
-
#errors ⇒ Array
get all errors from lexicals and reviews.
-
#initialize(options = {}) ⇒ Runner
constructor
initialize the runner.
-
#inline_disable(filename, content) ⇒ Object
disable check by inline comment the file.
-
#lexical(filename, content) ⇒ Object
lexical analysis the file.
-
#prepare(filename, content) ⇒ Object
prepare the file.
-
#review(filename, content) ⇒ Object
review the file.
Constructor Details
#initialize(options = {}) ⇒ Runner
initialize the runner.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/rails_best_practices/core/runner.rb', line 45 def initialize( = {}) @config = self.class.config_path lexicals = Array([:lexicals]) prepares = Array([:prepares]) reviews = Array([:reviews]) checks_loader = ChecksLoader.new(@config) @lexicals = lexicals.empty? ? checks_loader.load_lexicals : lexicals @prepares = prepares.empty? ? load_prepares : prepares @reviews = reviews.empty? ? checks_loader.load_reviews : reviews load_plugin_reviews if reviews.empty? @lexical_checker ||= CodeAnalyzer::CheckingVisitor::Plain.new(checkers: @lexicals) @plain_prepare_checker ||= CodeAnalyzer::CheckingVisitor::Plain.new( checkers: @prepares.select { |checker| checker.is_a? Prepares::GemfilePrepare } ) @default_prepare_checker ||= CodeAnalyzer::CheckingVisitor::Default.new( checkers: @prepares.reject { |checker| checker.is_a? Prepares::GemfilePrepare } ) @review_checker ||= CodeAnalyzer::CheckingVisitor::Default.new(checkers: @reviews) @inlnie_disable ||= InlineDisables::InlineDisable.new @inline_disable_checker ||= CodeAnalyzer::CheckingVisitor::Plain.new(checkers: [@inlnie_disable]) end |
Class Attribute Details
.base_path ⇒ String
get the base path, by default, the base path is current path.
29 30 31 |
# File 'lib/rails_best_practices/core/runner.rb', line 29 def base_path @base_path || '.' end |
.config_path ⇒ String
get the configuration path, if will default to config/rails_best_practices.yml
36 37 38 39 |
# File 'lib/rails_best_practices/core/runner.rb', line 36 def config_path custom_config = @config_path || File.join(Runner.base_path, 'config/rails_best_practices.yml') File.exist?(custom_config) ? custom_config : RailsBestPractices::Analyzer::DEFAULT_CONFIG end |
Instance Attribute Details
#checks ⇒ Object (readonly)
Returns the value of attribute checks.
21 22 23 |
# File 'lib/rails_best_practices/core/runner.rb', line 21 def checks @checks end |
Instance Method Details
#after_inline_disable ⇒ Object
121 122 123 |
# File 'lib/rails_best_practices/core/runner.rb', line 121 def after_inline_disable @inline_disable_checker.after_check end |
#after_lexical ⇒ Object
81 82 83 |
# File 'lib/rails_best_practices/core/runner.rb', line 81 def after_lexical @lexical_checker.after_check end |
#after_prepare ⇒ Object
94 95 96 97 |
# File 'lib/rails_best_practices/core/runner.rb', line 94 def after_prepare @plain_prepare_checker.after_check @default_prepare_checker.after_check end |
#after_review ⇒ Object
108 109 110 |
# File 'lib/rails_best_practices/core/runner.rb', line 108 def after_review @review_checker.after_check end |
#errors ⇒ Array
get all errors from lexicals and reviews.
128 129 130 131 132 133 |
# File 'lib/rails_best_practices/core/runner.rb', line 128 def errors @errors ||= begin reported_errors = (@reviews + @lexicals).collect(&:errors).flatten reported_errors.reject { |error| @inlnie_disable.disabled?(error) } end end |
#inline_disable(filename, content) ⇒ Object
disable check by inline comment the file.
116 117 118 119 |
# File 'lib/rails_best_practices/core/runner.rb', line 116 def inline_disable(filename, content) content = parse_html_template(filename, content) @inline_disable_checker.check(filename, content) end |
#lexical(filename, content) ⇒ Object
lexical analysis the file.
77 78 79 |
# File 'lib/rails_best_practices/core/runner.rb', line 77 def lexical(filename, content) @lexical_checker.check(filename, content) end |
#prepare(filename, content) ⇒ Object
prepare the file.
89 90 91 92 |
# File 'lib/rails_best_practices/core/runner.rb', line 89 def prepare(filename, content) @plain_prepare_checker.check(filename, content) @default_prepare_checker.check(filename, content) end |
#review(filename, content) ⇒ Object
review the file.
103 104 105 106 |
# File 'lib/rails_best_practices/core/runner.rb', line 103 def review(filename, content) content = parse_html_template(filename, content) @review_checker.check(filename, content) end |