Class: FindMethodInPath

Inherits:
Parser::AST::Processor
  • Object
show all
Includes:
RuboCop::AST::Traversal
Defined in:
app/services/find_method_in_path.rb

Overview

require ‘fast’

Defined Under Namespace

Classes: AddMethod, DisplayMethod, FindMethod, Replace

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(path_id) ⇒ Object



6
7
8
# File 'app/services/find_method_in_path.rb', line 6

def self.call(path_id)
  new.call(path_id)
end

Instance Method Details

#call(path_id) ⇒ Object

Have a “Exists?” method that checks to see if something exists If it doesn’t use an Insert class and define which section it should go into If it does, work out the differences(?) and update them



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/services/find_method_in_path.rb', line 14

def call(path_id)
  path = Path.find(path_id)
  code = File.readlines(path.path).join
  source = RuboCop::ProcessedSource.new(code, 2.7)

  path.events.call.each_with_object({}) do |event, methods|
    methods[event.method.to_sym] = ''

    node = FindMethod.call(
      type: :def,
      name: event.method.to_sym,
      source: source
    )

    next unless node.present?

    methods[event.method.to_sym] = DisplayMethod.call(node: node, code: code)
  end
end