Class: SourceRoute::TpResult
Overview
what solution is good for summarize attrs that required to be included
Constant Summary collapse
- TP_ATTRS =
attrs from TracePoint object
[:event, :defined_class, :event, :lineno, :method_id, :path, :raised_exception, :return_value].freeze
- INNER_ATTRS =
attrs generated from TracePoint.binding
[:local_var, :instance_var, :params_var].freeze
- CUSTOM_ATTRS =
customized attrs for build html output
[:order_id, :parent_ids, :direct_child_order_ids, :has_return_value, :parent_length, :tp_self_refer].freeze
Instance Method Summary collapse
- #==(other) ⇒ Object
- #call_event? ⇒ Boolean
- #collect_required_data ⇒ Object
- #found_opposite ⇒ Object
- #get_attrs ⇒ Object
- #get_instance_var ⇒ Object
- #get_local_or_params_var ⇒ Object
- #get_self_refer ⇒ Object
-
#initialize(tp_ins) ⇒ TpResult
constructor
The tricky part is can’t call method on @tp_ins outside trace block finished it could be a security limitation in ruby TracePoint object so collect_required_data can only run once and immediately.
- #locate_opposite? ⇒ Boolean
- #matched? ⇒ Boolean
- #return_event? ⇒ Boolean
- #return_tp_assign_call_tp(call_tp) ⇒ Object
-
#stringify ⇒ Object
todo: this is a mutable method not a good solution.
- #to_hash ⇒ Object
Constructor Details
#initialize(tp_ins) ⇒ TpResult
The tricky part is can’t call method on @tp_ins outside trace block finished it could be a security limitation in ruby TracePoint object so collect_required_data can only run once and immediately
22 23 24 25 |
# File 'lib/source_route/tp_result.rb', line 22 def initialize(tp_ins) @tp_ins = tp_ins collect_required_data end |
Instance Method Details
#==(other) ⇒ Object
43 44 45 46 |
# File 'lib/source_route/tp_result.rb', line 43 def ==(other) tp_self_refer == other.tp_self_refer and # path == other.path and lineno == other.lineno method_id == other.method_id and defined_class == other.defined_class end |
#call_event? ⇒ Boolean
39 40 41 |
# File 'lib/source_route/tp_result.rb', line 39 def call_event? event == :call end |
#collect_required_data ⇒ Object
101 102 103 104 105 106 107 108 |
# File 'lib/source_route/tp_result.rb', line 101 def collect_required_data get_attrs get_self_refer get_local_or_params_var if SourceRoute.proxy.config.include_local_var get_instance_var if SourceRoute.proxy.config.include_instance_var and return_event? self end |
#found_opposite ⇒ Object
27 28 29 |
# File 'lib/source_route/tp_result.rb', line 27 def found_opposite @opposite_exist = true end |
#get_attrs ⇒ Object
110 111 112 113 114 115 116 |
# File 'lib/source_route/tp_result.rb', line 110 def get_attrs GenerateResult.wanted_attributes(@tp_ins.event).each do |key| if @tp_ins.respond_to?(key) send("#{key}=", @tp_ins.send(key)) end end end |
#get_instance_var ⇒ Object
140 141 142 143 144 145 146 |
# File 'lib/source_route/tp_result.rb', line 140 def get_instance_var instance_var_hash = {} @tp_ins.self.instance_variables.each do |key| instance_var_hash[key] = @tp_ins.self.instance_variable_get(key).source_route_display end self.instance_var = instance_var_hash if instance_var_hash != {} end |
#get_local_or_params_var ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/source_route/tp_result.rb', line 123 def get_local_or_params_var local_var_hash = {} # Warn: @tp_ins.binding.eval('local_variables') =! @tp_ins.binding.send('local_variables') @tp_ins.binding.eval('local_variables').each do |v| # I need comment out why i need source_route_display # must be some strange variables require it local_var_hash[v] = @tp_ins.binding.local_variable_get(v).source_route_display end if local_var_hash != {} if call_event? self.params_var = local_var_hash elsif return_event? # what about other event? self.local_var = local_var_hash end end end |
#get_self_refer ⇒ Object
118 119 120 121 |
# File 'lib/source_route/tp_result.rb', line 118 def get_self_refer self.tp_self_refer = SourceRoute.proxy.result_builder.tp_self_caches .map(&:__id__).index(@tp_ins.self.__id__) end |
#locate_opposite? ⇒ Boolean
31 32 33 |
# File 'lib/source_route/tp_result.rb', line 31 def locate_opposite? @opposite_exist end |
#matched? ⇒ Boolean
48 49 50 |
# File 'lib/source_route/tp_result.rb', line 48 def matched? @matched end |
#return_event? ⇒ Boolean
35 36 37 |
# File 'lib/source_route/tp_result.rb', line 35 def return_event? event == :return end |
#return_tp_assign_call_tp(call_tp) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/source_route/tp_result.rb', line 52 def return_tp_assign_call_tp(call_tp) @matched = true call_tp.return_value = return_value call_tp.local_var = local_var unless local_var.nil? call_tp.instance_var = instance_var unless instance_var.nil? end |
#stringify ⇒ Object
todo: this is a mutable method not a good solution. we should use it on the return hash of method to_hash
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/source_route/tp_result.rb', line 83 def stringify if GenerateResult.wanted_attributes(event).include?(:defined_class) self.defined_class = defined_class.to_s end if GenerateResult.wanted_attributes(event).include?(:return_value) if return_value.nil? or return_value.is_a? Symbol or # ActiveRecord::ConnectionAdapters::Column override method == (return_value.is_a? String and return_value == '') self.return_value = return_value.inspect else self.return_value = return_value.to_s end end self.event = event.to_s self.method_id = method_id.to_s self end |
#to_hash ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/source_route/tp_result.rb', line 59 def to_hash stringify ret_hash = GenerateResult.wanted_attributes(event).inject({}) do |memo, k| memo[k.to_s] = send(k) memo end if SourceRoute.proxy.config.event.include?(:return) ret_hash['return_value'] = return_value.nil? ? return_value.inspect : return_value end (INNER_ATTRS + CUSTOM_ATTRS).each do |k| ret_hash[k.to_s] = send(k) if send(k) end ret_hash['return_value_class'] = ret_hash['return_value'].class.name ret_hash['params_var_class'] = ret_hash['params_var'].class.name if ret_hash['params_var'] ret_hash['local_var_class'] = ret_hash['local_var'].class.name if ret_hash['local_var'] ret_hash['instance_var_class'] = ret_hash['instance_var'].class.name if ret_hash['instance_var'] ret_hash end |