Class: SourceRoute::TpResultChain

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/source_route/tp_result_chain.rb

Overview

delegate to Array

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTpResultChain

Returns a new instance of TpResultChain.



11
12
13
# File 'lib/source_route/tp_result_chain.rb', line 11

def initialize
  @chain = []
end

Instance Attribute Details

#chainObject (readonly)

Returns the value of attribute chain.



4
5
6
# File 'lib/source_route/tp_result_chain.rb', line 4

def chain
  @chain
end

Instance Method Details

#call_chainObject



15
16
17
# File 'lib/source_route/tp_result_chain.rb', line 15

def call_chain
  select(&:call_event?)
end

#deep_clonedObject



57
58
59
# File 'lib/source_route/tp_result_chain.rb', line 57

def deep_cloned
  chain.map { |r| r.clone }
end

#import_return_value_to_call_chainObject



23
24
25
26
27
28
29
30
31
# File 'lib/source_route/tp_result_chain.rb', line 23

def import_return_value_to_call_chain
  call_chain.each do |ctp|
    matched_return_tp = return_chain.reject(&:matched?).detect {|rtp| rtp == ctp}

    unless matched_return_tp.nil?
      matched_return_tp.return_assign_call(ctp)
    end
  end
end

#parent_length_listObject



53
54
55
# File 'lib/source_route/tp_result_chain.rb', line 53

def parent_length_list
  call_chain.map { |tp| tp[:parent_length] }.uniq.sort
end

#return_chainObject



19
20
21
# File 'lib/source_route/tp_result_chain.rb', line 19

def return_chain
  select(&:return_event?)
end

#stringifyObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/source_route/tp_result_chain.rb', line 61

def stringify
  deep_cloned.map do |tr|
    # to_s is safer than inspect
    # ex: inspect on ActiveRecord_Relation may crash
    tr[:defined_class] = tr[:defined_class].to_s if tr.has_key?(:defined_class)
    if tr.has_key?(:return_value)
      if tr[:return_value].nil? or tr[:return_value].is_a? Symbol or
        # ActiveRecord::ConnectionAdapters::Column override method ==
          (tr[:return_value].is_a? String and tr[:return_value] == '')
        tr[:return_value] = tr[:return_value].inspect
      else
        tr[:return_value] = tr[:return_value].to_s
      end
    end
    tr
  end
end

#treeize_call_chainObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/source_route/tp_result_chain.rb', line 33

def treeize_call_chain
  init_order_id_and_parent_ids
  call_chain.each do |tpr|
    return_tpr = return_chain.reject { |c| c[:record_parent] }.find do |rtpr|
      rtpr[:tp_self] == tpr[:tp_self] and rtpr[:defined_class] == tpr[:defined_class] and rtpr[:method_id] == tpr[:method_id]
    end
    unless return_tpr.nil?
      return_tpr[:record_parent] = true
      start_index, end_index = tpr[:order_id], return_tpr[:order_id]
      unless end_index == start_index + 1
        values_at(start_index+1 ... end_index).select { |tpr| tpr[:event] == :call }.each do |tpr|
          tpr[:parent_ids].push start_index
        end
      end
    end
  end

  cal_parent_length
end