class RailsBestPractices::Core::Check
def add_error(message, filename = @node.file, line_number = @node.line_number)
-
line_number,
(Integer
) -- is the line number of the source code which is reviewing -
filename,
(String
) -- is the filename of source code -
message,
(String
) -- is the string message for violation of the rails best practice
def add_error(message, filename = @node.file, line_number = @node.line_number) errors << RailsBestPractices::Core::Error.new( filename: filename, line_number: line_number, message: message, type: self.class.to_s, url: url ) end
def debug
def debug @debug = true end
def debug?
def debug? @debug == true end
def errors
def errors @errors ||= [] end
def initialize(options = {})
def initialize(options = {}) options.each do |key, value| instance_variable_set("@#{key}", value) end end
def is_ignored?(node_file)
def is_ignored?(node_file) regex_ignored_files.map { |r| !!r.match(node_file) }.inject(:|) end
def is_interesting_file?(node_file)
def is_interesting_file?(node_file) interesting_files.any? do |pattern| if pattern == ALL_FILES node_file =~ pattern && node_file !~ SKIP_FILES else node_file =~ pattern end end end
def method_missing(method_name, *args)
end_call
start_call
end_def
start_def
method_missing to catch all start and end process for each node type, like
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
def parse_file?(node_file)
-
(Boolean)
- true if the check will need to parse the file.
Parameters:
-
the
(String
) -- file name of node.
def parse_file?(node_file) node_file.is_a?(String) && is_interesting_file?(node_file) && !is_ignored?(node_file) end
def regex_ignored_files
def regex_ignored_files @regex_ignored_files ||= Array(@ignored_files).map { |pattern| Regexp.new(pattern) } end
def url
-
(String)
- the url of rails best practice
def url self.class.url end
def url(url = nil)
def url(url = nil) url ? @url = url : @url end