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.
Instance Attribute Summary collapse
-
#checks ⇒ Object
readonly
Returns the value of attribute checks.
-
#color ⇒ Object
Returns the value of attribute color.
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#whiny ⇒ Object
Returns the value of attribute whiny.
Class Method Summary collapse
-
.base_path ⇒ String
get the base path, by default, the base path is current path.
-
.base_path=(path) ⇒ Object
set the base path.
Instance Method Summary collapse
-
#after_lexical ⇒ Object
After lexical method.
-
#after_prepare ⇒ Object
provide a handler after all files reviewed.
-
#after_review ⇒ Object
provide a handler after all files reviewed.
-
#errors ⇒ Array
get all errors from lexicals and reviews.
-
#initialize(options = {}) ⇒ Runner
constructor
initialize the runner.
-
#lexical(filename, content) ⇒ Object
lexical analysis the file.
-
#lexical_file(filename) ⇒ Object
lexical analysis the file.
-
#prepare(filename, content) ⇒ Object
parepare a file’s content with filename.
-
#prepare_file(filename) ⇒ Object
parapare the file.
-
#results ⇒ Hash
get the results for all active checkers (reviews and lexicals).
-
#review(filename, content) ⇒ Object
review a file’s content with filename.
-
#review_file(filename) ⇒ Object
review the file.
Constructor Details
#initialize(options = {}) ⇒ Runner
initialize the runner.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rails_best_practices/core/runner.rb', line 37 def initialize(={}) custom_config = File.join(Runner.base_path, 'config/rails_best_practices.yml') @config = File.exists?(custom_config) ? custom_config : RailsBestPractices::Analyzer::DEFAULT_CONFIG lexicals = Array([:lexicals]) prepares = Array([:prepares]) reviews = Array([:reviews]) @lexicals = lexicals.empty? ? load_lexicals : lexicals @prepares = prepares.empty? ? load_prepares : prepares @reviews = reviews.empty? ? load_reviews : reviews load_plugin_reviews if reviews.empty? @checker ||= CheckingVisitor.new(:prepares => @prepares, :reviews => @reviews, :lexicals => @lexicals) @debug = false @whiny = false end |
Instance Attribute Details
#checks ⇒ Object (readonly)
Returns the value of attribute checks.
17 18 19 |
# File 'lib/rails_best_practices/core/runner.rb', line 17 def checks @checks end |
#color ⇒ Object
Returns the value of attribute color.
18 19 20 |
# File 'lib/rails_best_practices/core/runner.rb', line 18 def color @color end |
#debug ⇒ Object
Returns the value of attribute debug.
18 19 20 |
# File 'lib/rails_best_practices/core/runner.rb', line 18 def debug @debug end |
#whiny ⇒ Object
Returns the value of attribute whiny.
18 19 20 |
# File 'lib/rails_best_practices/core/runner.rb', line 18 def whiny @whiny end |
Class Method Details
.base_path ⇒ String
get the base path, by default, the base path is current path.
30 31 32 |
# File 'lib/rails_best_practices/core/runner.rb', line 30 def self.base_path @base_path || "." end |
.base_path=(path) ⇒ Object
set the base path.
23 24 25 |
# File 'lib/rails_best_practices/core/runner.rb', line 23 def self.base_path=(path) @base_path = path end |
Instance Method Details
#after_lexical ⇒ Object
After lexical method.
127 |
# File 'lib/rails_best_practices/core/runner.rb', line 127 def after_lexical; end |
#after_prepare ⇒ Object
provide a handler after all files reviewed.
130 131 132 133 134 135 136 |
# File 'lib/rails_best_practices/core/runner.rb', line 130 def after_prepare filename = "rails_best_practices.after_prepare" content = "class RailsBestPractices::AfterPrepare; end" node = parse_ruby(filename, content) node.file = filename node.prepare(@checker) end |
#after_review ⇒ Object
provide a handler after all files reviewed.
139 140 141 142 143 144 145 |
# File 'lib/rails_best_practices/core/runner.rb', line 139 def after_review filename = "rails_best_practices.after_review" content = "class RailsBestPractices::AfterReview; end" node = parse_ruby(filename, content) node.file = filename node.review(@checker) end |
#errors ⇒ Array
get all errors from lexicals and reviews.
115 116 117 |
# File 'lib/rails_best_practices/core/runner.rb', line 115 def errors (@reviews + @lexicals).collect {|check| check.errors}.flatten end |
#lexical(filename, content) ⇒ Object
lexical analysis the file.
59 60 61 62 |
# File 'lib/rails_best_practices/core/runner.rb', line 59 def lexical(filename, content) puts filename if @debug @checker.lexical(filename, content) end |
#lexical_file(filename) ⇒ Object
lexical analysis the file.
67 68 69 |
# File 'lib/rails_best_practices/core/runner.rb', line 67 def lexical_file(filename) lexical(filename, read_file(filename)) end |
#prepare(filename, content) ⇒ Object
parepare a file’s content with filename.
75 76 77 78 79 80 81 82 |
# File 'lib/rails_best_practices/core/runner.rb', line 75 def prepare(filename, content) puts filename if @debug node = parse_ruby(filename, content) if node node.file = filename node.prepare(@checker) end end |
#prepare_file(filename) ⇒ Object
parapare the file.
87 88 89 |
# File 'lib/rails_best_practices/core/runner.rb', line 87 def prepare_file(filename) prepare(filename, read_file(filename)) end |
#results ⇒ Hash
get the results for all active checkers (reviews and lexicals).
122 123 124 |
# File 'lib/rails_best_practices/core/runner.rb', line 122 def results (@reviews + @lexicals).map &:result end |
#review(filename, content) ⇒ Object
review a file’s content with filename.
95 96 97 98 99 100 101 102 103 |
# File 'lib/rails_best_practices/core/runner.rb', line 95 def review(filename, content) puts filename if @debug content = parse_html_template(filename, content) node = parse_ruby(filename, content) if node node.file = filename node.review(@checker) end end |
#review_file(filename) ⇒ Object
review the file.
108 109 110 |
# File 'lib/rails_best_practices/core/runner.rb', line 108 def review_file(filename) review(filename, read_file(filename)) end |