Class: MethodLog::MethodFinder
- Inherits:
-
Ripper
- Object
- Ripper
- MethodLog::MethodFinder
- Defined in:
- lib/method_log/method_finder.rb
Instance Method Summary collapse
- #find(method_identifier) ⇒ Object
-
#initialize(source_file: nil) ⇒ MethodFinder
constructor
A new instance of MethodFinder.
- #on_class(*args) ⇒ Object
- #on_const(name) ⇒ Object
- #on_def(name, *args) ⇒ Object
- #on_kw(name) ⇒ Object
- #on_module(*args) ⇒ Object
Constructor Details
#initialize(source_file: nil) ⇒ MethodFinder
Returns a new instance of MethodFinder.
7 8 9 10 11 12 13 14 |
# File 'lib/method_log/method_finder.rb', line 7 def initialize(source_file: nil) super(source_file.source) @source_file = source_file @namespaces = [] @methods = {} @at_scope_start = false parse end |
Instance Method Details
#find(method_identifier) ⇒ Object
16 17 18 |
# File 'lib/method_log/method_finder.rb', line 16 def find(method_identifier) @methods[method_identifier] end |
#on_class(*args) ⇒ Object
43 44 45 |
# File 'lib/method_log/method_finder.rb', line 43 def on_class(*args) @namespaces.pop end |
#on_const(name) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/method_log/method_finder.rb', line 29 def on_const(name) if @at_scope_start @namespaces << name @at_scope_start = false end end |
#on_def(name, *args) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/method_log/method_finder.rb', line 36 def on_def(name, *args) identifier = "#{@namespaces.join('::')}##{name}" lines = (@line_number - 1)..(lineno - 1) definition = MethodDefinition.new(source_file: @source_file, lines: lines) @methods[identifier] = definition end |
#on_kw(name) ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/method_log/method_finder.rb', line 20 def on_kw(name) case name when 'def' @line_number = lineno when 'class', 'module' @at_scope_start = true end end |
#on_module(*args) ⇒ Object
47 48 49 |
# File 'lib/method_log/method_finder.rb', line 47 def on_module(*args) @namespaces.pop end |