Class: Solargraph::Rails::Walker::Hook

Inherits:
Object
  • Object
show all
Defined in:
lib/solargraph/rails/walker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node_type, args, &block) ⇒ Hook

Returns a new instance of Hook.



6
7
8
9
10
# File 'lib/solargraph/rails/walker.rb', line 6

def initialize(node_type, args, &block)
  @node_type = node_type
  @args = args
  @proc = Proc.new(&block)
end

Instance Attribute Details

#node_typeObject (readonly)

Returns the value of attribute node_type.



5
6
7
# File 'lib/solargraph/rails/walker.rb', line 5

def node_type
  @node_type
end

Instance Method Details

#visit(node) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/solargraph/rails/walker.rb', line 12

def visit(node)
  return unless matches?(node)

  if @proc.arity == 1
    @proc.call(node)
  elsif @proc.arity == 2
    walker = Walker.new(node)
    @proc.call(node, walker)
    walker.walk
  end
end