Class: FindMethodFromEvent

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

Overview

require ‘fast’

Defined Under Namespace

Classes: DisplayMethod, FindMethod

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.call(event) ⇒ Object



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

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

Instance Method Details

#call(event) ⇒ 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
# File 'app/services/find_method_from_event.rb', line 14

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

  return unless source.present?

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

  return unless node.present?

  DisplayMethod
    .call(node: node, code: code)
    .split("\n")
end