Class: Phlexing::Visitor

Inherits:
SyntaxTree::Visitor
  • Object
show all
Includes:
Helpers
Defined in:
lib/phlexing/visitor.rb

Constant Summary

Constants included from Helpers

Helpers::KNOWN_ELEMENTS, Helpers::SVG_ELEMENTS

Instance Method Summary collapse

Methods included from Helpers

#arg, #block, #blocklist, #braces, #children?, #interpolate, #known_rails_helpers, #multiple_children?, #newline, #output, #parens, #quote, #routes_helpers, #siblings?, #string_output?, #symbol, #tag_name, #unescape, #unwrap_erb, #whitespace

Constructor Details

#initialize(analyzer) ⇒ Visitor

Returns a new instance of Visitor.



10
11
12
# File 'lib/phlexing/visitor.rb', line 10

def initialize(analyzer)
  @analyzer = analyzer
end

Instance Method Details

#visit_call(node) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/phlexing/visitor.rb', line 29

def visit_call(node)
  if node.receiver
    case node.receiver
    when SyntaxTree::VarRef
      value = node.receiver.value.value

      case node.receiver.value
      when SyntaxTree::IVar
        @analyzer.ivars << value.from(1)
      when SyntaxTree::Ident
        @analyzer.idents << value
      end

      @analyzer.calls << value

    when SyntaxTree::VCall
      case node.receiver.value
      when SyntaxTree::Ident
        @analyzer.calls << node.receiver.value.value
      end

    when SyntaxTree::Ident
      value = node.receiver.value.value.value

      @analyzer.idents << value unless value.ends_with?("?")
      @analyzer.calls << value

    when SyntaxTree::Const
      @analyzer.calls << node.receiver.value
    end

  elsif node.receiver.nil? && node.operator.nil?
    case node.message
    when SyntaxTree::Ident
      if node.message.value.end_with?("?") || node.child_nodes[3].is_a?(SyntaxTree::ArgParen)
        unless rails_helper?(node.message.value)
          @analyzer.instance_methods << node.message.value
        end
        @analyzer.calls << node.message.value
      else
        @analyzer.idents << node.message.value
      end
    end
  end

  super
end

#visit_command(node) ⇒ Object



22
23
24
25
26
27
# File 'lib/phlexing/visitor.rb', line 22

def visit_command(node)
  unless rails_helper?(node.message.value)
    @analyzer.instance_methods << node.message.value
  end
  super
end

#visit_const(node) ⇒ Object



18
19
20
# File 'lib/phlexing/visitor.rb', line 18

def visit_const(node)
  @analyzer.consts << node.value
end

#visit_ident(node) ⇒ Object



83
84
85
86
87
# File 'lib/phlexing/visitor.rb', line 83

def visit_ident(node)
  unless rails_helper?(node.value)
    @analyzer.idents << node.value
  end
end

#visit_ivar(node) ⇒ Object



14
15
16
# File 'lib/phlexing/visitor.rb', line 14

def visit_ivar(node)
  @analyzer.ivars << node.value.from(1)
end

#visit_vcall(node) ⇒ Object



77
78
79
80
81
# File 'lib/phlexing/visitor.rb', line 77

def visit_vcall(node)
  unless rails_helper?(node.value.value)
    @analyzer.locals << node.value.value
  end
end