Class: MethodLog::MethodFinder

Inherits:
Parser::AST::Processor
  • Object
show all
Defined in:
lib/method_log/method_finder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_file) ⇒ MethodFinder

Returns a new instance of MethodFinder.



12
13
14
15
16
17
18
# File 'lib/method_log/method_finder.rb', line 12

def initialize(source_file)
  @source_file = source_file
  @scope = Scope::Root.new
  @methods = {}
  ast = Parser::CurrentRuby.parse(source_file.source)
  process(ast)
end

Instance Attribute Details

#methodsObject (readonly)

Returns the value of attribute methods.



10
11
12
# File 'lib/method_log/method_finder.rb', line 10

def methods
  @methods
end

Instance Method Details

#find(method_identifier) ⇒ Object



20
21
22
# File 'lib/method_log/method_finder.rb', line 20

def find(method_identifier)
  @methods[method_identifier]
end

#on_def(node) ⇒ Object



38
39
40
41
42
# File 'lib/method_log/method_finder.rb', line 38

def on_def(node)
  name, args_node, body_node = *node
  record_method_definition(@scope, name, node)
  super
end

#on_defs(node) ⇒ Object



44
45
46
47
48
49
# File 'lib/method_log/method_finder.rb', line 44

def on_defs(node)
  definee_node, name, args_node, body_node = *node
  scope = singleton_scope_for(definee_node)
  record_method_definition(scope, name, node)
  super
end

#on_module(node) ⇒ Object Also known as: on_class



24
25
26
27
28
29
# File 'lib/method_log/method_finder.rb', line 24

def on_module(node)
  const_node = node.children.first
  constants = process_const(const_node)
  new_constant = constants.pop
  with_scope(@scope.for(constants).define(new_constant)) { super }
end

#on_sclass(node) ⇒ Object



33
34
35
36
# File 'lib/method_log/method_finder.rb', line 33

def on_sclass(node)
  target_node = node.children.first
  with_scope(singleton_scope_for(target_node)) { super }
end