Class: RailsBestPractices::Core::Check
- Inherits:
-
Object
- Object
- RailsBestPractices::Core::Check
- Defined in:
- lib/rails_best_practices/core/check.rb
Overview
A Check class that takes charge of checking the sexp.
Direct Known Subclasses
Lexicals::RemoveTabCheck, Lexicals::RemoveTrailingWhitespaceCheck, Prepares::MailerPrepare, Prepares::ModelPrepare, Prepares::SchemaPrepare, Reviews::Review
Constant Summary collapse
- NODE_TYPES =
only nodes whose node_type is in NODE_TYPE will be reviewed.
[:call, :defn, :defs, :if, :class, :module, :lasgn, :iasgn, :ivar, :lvar, :block, :iter, :const]
- CONTROLLER_FILES =
/controllers\/.*\.rb$/
- MIGRATION_FILES =
/db\/migrate\/.*\.rb$/
- MODEL_FILES =
/models\/.*\.rb$/
- MAILER_FILES =
/models\/.*mailer\.rb$|mailers\/.*mailer\.rb/
- VIEW_FILES =
/views\/.*\.(erb|haml)$/
- PARTIAL_VIEW_FILES =
/views\/.*\/_.*\.(erb|haml)$/
- ROUTE_FILE =
/config\/routes\.rb/
- SCHEMA_FILE =
/db\/schema\.rb/
- HELPER_FILES =
/helpers.*\.rb$/
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Instance Method Summary collapse
-
#add_error(error, file = @node.file, line = @node.line) ⇒ Object
add error if source code violates rails best practice.
-
#initialize ⇒ Check
constructor
A new instance of Check.
-
#interesting_files ⇒ Object
default interesting files.
-
#interesting_nodes ⇒ Object
default interesting nodes.
-
#method_missing(method_name, *args) ⇒ Object
method_missing to catch all start and end process for each node type, like.
-
#node_end(node) ⇒ Object
delegate to end_### according to the node_type, like.
-
#node_start(node) ⇒ Object
delegate to start_### according to the node_type, like.
-
#url ⇒ String
default url is empty.
Constructor Details
#initialize ⇒ Check
Returns a new instance of Check.
21 22 23 |
# File 'lib/rails_best_practices/core/check.rb', line 21 def initialize @errors = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args) ⇒ Object
method_missing to catch all start and end process for each node type, like
start_defn
end_defn
start_call
end_call
if there is a “debug” method defined in check, each node will be output.
80 81 82 83 84 85 86 87 88 |
# File 'lib/rails_best_practices/core/check.rb', line 80 def method_missing(method_name, *args) if method_name.to_s =~ /^start_/ p args if respond_to?(:debug) elsif method_name.to_s =~ /^end_/ # nothing to do else super end end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
19 20 21 |
# File 'lib/rails_best_practices/core/check.rb', line 19 def errors @errors end |
Instance Method Details
#add_error(error, file = @node.file, line = @node.line) ⇒ Object
add error if source code violates rails best practice.
error is the string message for violation of the rails best practice
file is the filename of source code
line is the line number of the source code which is reviewing
61 62 63 |
# File 'lib/rails_best_practices/core/check.rb', line 61 def add_error(error, file = @node.file, line = @node.line) @errors << RailsBestPractices::Core::Error.new("#{file}", "#{line}", error, url) end |
#interesting_files ⇒ Object
default interesting files.
31 32 33 |
# File 'lib/rails_best_practices/core/check.rb', line 31 def interesting_files /.*/ end |
#interesting_nodes ⇒ Object
default interesting nodes.
26 27 28 |
# File 'lib/rails_best_practices/core/check.rb', line 26 def interesting_nodes NODE_TYPES end |
#node_end(node) ⇒ Object
delegate to end_### according to the node_type, like
end_call
end_defn
52 53 54 55 |
# File 'lib/rails_best_practices/core/check.rb', line 52 def node_end(node) @node = node self.send("end_#{node.node_type}", node) end |
#node_start(node) ⇒ Object
delegate to start_### according to the node_type, like
start_call
start_defn
41 42 43 44 |
# File 'lib/rails_best_practices/core/check.rb', line 41 def node_start(node) @node = node self.send("start_#{node.node_type}", node) end |
#url ⇒ String
default url is empty.
68 69 70 |
# File 'lib/rails_best_practices/core/check.rb', line 68 def url "" end |