Method: SplitMethods#call

Defined in:
app/services/split_methods.rb

#call(event) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/services/split_methods.rb', line 10

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

  method_name = event.method.to_sym

  method = source.ast
                  .each_node
                  .select do |n|
                    # Will need to add method name here, and the delegate param
                    #
                    n.type == :def && method_name == n.method_name # || n.type == :send && n.method_name == :delegate
                  end

  method = method.first

  DisplayMethod.call(code: code, node: method)
rescue => e
  Rails.logger.info("Missing method: #{method_name}")
end