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
-
#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.
Constructor Details
#initialize(options = {}) ⇒ Runner
initialize the runner.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# 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::DEFAULT_CONFIG prepares = Array([:prepares]) reviews = Array([:reviews]) @lexicals = load_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
#errors ⇒ Array
get all errors from lexicals and reviews.
93 94 95 |
# File 'lib/rails_best_practices/core/runner.rb', line 93 def errors (@reviews + @lexicals).collect {|check| check.errors}.flatten end |
#lexical(filename, content) ⇒ Object
lexical analysis the file.
58 59 60 61 |
# File 'lib/rails_best_practices/core/runner.rb', line 58 def lexical(filename, content) puts filename if @debug @checker.lexical(filename, content) end |
#lexical_file(filename) ⇒ Object
lexical analysis the file.
66 67 68 |
# File 'lib/rails_best_practices/core/runner.rb', line 66 def lexical_file(filename) lexical(filename, File.open(filename, "r:UTF-8") { |f| f.read }) end |