Class: Woods::FlowAnalysis::OperationExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/woods/flow_analysis/operation_extractor.rb

Overview

Extracts operations from a method body AST in source line order.

Uses Ast::CallSiteExtractor for raw call sites, then classifies each into domain-meaningful operation types: calls, transactions, async enqueues, responses, conditionals, cycles, and dynamic dispatch.

Examples:

Extracting operations from a method body

parser = Ast::Parser.new
root = parser.parse(source)
method_node = root.find_all(:def).find { |n| n.method_name == "create" }
ops = OperationExtractor.new.extract(method_node)
ops.first[:type] #=> :call

Constant Summary collapse

TRANSACTION_METHODS =
%w[transaction with_lock].freeze
ASYNC_METHODS =
%w[perform_async perform_later perform_in perform_at].freeze
RESPONSE_METHODS =
%w[redirect_to head respond_with].freeze
DYNAMIC_DISPATCH_METHODS =
%w[send public_send].freeze

Instance Method Summary collapse

Instance Method Details

#extract(method_node) ⇒ Array<Hash>

Extract operations from a method definition node in source line order.

Parameters:

  • method_node (Ast::Node)

    A :def or :defs node

Returns:

  • (Array<Hash>)

    Operations ordered by source line



33
34
35
36
37
38
39
# File 'lib/woods/flow_analysis/operation_extractor.rb', line 33

def extract(method_node)
  return [] unless method_node.is_a?(Ast::Node)

  operations = []
  walk(method_node, operations)
  operations
end