Class: Roodi::Checks::Check

Inherits:
Object
  • Object
show all
Defined in:
lib/roodi/checks/check.rb

Overview

Base class for all the checks

Constant Summary collapse

NODE_TYPES =
[:defn, :module, :resbody, :lvar, :cvar, :class, :if, :while, :until, :for, :rescue, :case, :when, :and, :or]

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCheck

Returns a new instance of Check.



24
25
26
# File 'lib/roodi/checks/check.rb', line 24

def initialize
  @errors = []
end

Class Method Details

.make(options = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/roodi/checks/check.rb', line 12

def make(options = nil)
  check = new
  if options
    options.each do |name, value|
      check.send("#{name}=", value)
    end
  end
  check
end

Instance Method Details

#add_error(error, filename = @node.file, line = @node.line) ⇒ Object



67
68
69
70
# File 'lib/roodi/checks/check.rb', line 67

def add_error(error, filename = @node.file, line = @node.line)
  @errors ||= []
  @errors << Roodi::Core::Error.new("#{filename}", "#{line}", error)
end

#end_file(filename) ⇒ Object



42
43
# File 'lib/roodi/checks/check.rb', line 42

def end_file(filename)
end

#errorsObject



72
73
74
# File 'lib/roodi/checks/check.rb', line 72

def errors
  @errors
end

#evaluate_end(node) ⇒ Object



48
49
# File 'lib/roodi/checks/check.rb', line 48

def evaluate_end(node)
end

#evaluate_node(position, node) ⇒ Object



51
52
53
54
55
# File 'lib/roodi/checks/check.rb', line 51

def evaluate_node(position, node)
  @node = node
  eval_method = "evaluate_#{position}_#{node.node_type}"
  self.send(eval_method, node)
end

#evaluate_node_end(node) ⇒ Object



62
63
64
65
# File 'lib/roodi/checks/check.rb', line 62

def evaluate_node_end(node)
  evaluate_node(:end, node)
  evaluate_end(node)
end

#evaluate_node_start(node) ⇒ Object



57
58
59
60
# File 'lib/roodi/checks/check.rb', line 57

def evaluate_node_start(node)
  evaluate_node(:start, node)
  evaluate_start(node)
end

#evaluate_start(node) ⇒ Object



45
46
# File 'lib/roodi/checks/check.rb', line 45

def evaluate_start(node)
end

#position(offset = 0) ⇒ Object



35
36
37
# File 'lib/roodi/checks/check.rb', line 35

def position(offset = 0)
  "#{@line[2]}:#{@line[1] + offset}"
end

#start_file(filename) ⇒ Object



39
40
# File 'lib/roodi/checks/check.rb', line 39

def start_file(filename)
end