Class: CallSearcher::MethodCall

Inherits:
Object
  • Object
show all
Defined in:
lib/call_searcher/method_call.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node:, context:) ⇒ MethodCall

Returns a new instance of MethodCall.



9
10
11
12
# File 'lib/call_searcher/method_call.rb', line 9

def initialize(node:, context:)
  @node = node
  @context = context
end

Instance Attribute Details

#nodeObject (readonly)

Returns the value of attribute node.



7
8
9
# File 'lib/call_searcher/method_call.rb', line 7

def node
  @node
end

Instance Method Details

#github_urlObject



44
45
46
47
48
# File 'lib/call_searcher/method_call.rb', line 44

def github_url
  if @context.github
    "https://github.com/#{@context.github}/blob/master/#{relative_path}#L#{@node.first_lineno}"
  end
end

#inspectObject



40
41
42
# File 'lib/call_searcher/method_call.rb', line 40

def inspect
  "<#{self.class} #{type}@#{location}>"
end

#locationObject



36
37
38
# File 'lib/call_searcher/method_call.rb', line 36

def location
  "#{@context.path}:#{@node.first_lineno}"
end

#midObject



27
28
29
30
31
32
33
34
# File 'lib/call_searcher/method_call.rb', line 27

def mid
  case type
  when :FCALL, :VCALL
    node.children[0]
  else
    node.children[1]
  end
end

#receiverObject



18
19
20
21
22
23
24
25
# File 'lib/call_searcher/method_call.rb', line 18

def receiver
  case type
  when :FCALL, :VCALL
    nil
  else
    node.children[0]
  end
end

#relative_pathObject



50
51
52
# File 'lib/call_searcher/method_call.rb', line 50

def relative_path
  Pathname.new(@context.path).relative_path_from(Pathname.new(@context.root_dir))
end

#typeObject



14
15
16
# File 'lib/call_searcher/method_call.rb', line 14

def type
  @type ||= node.type
end