Class: SourceRoute::Wrapper
- Inherits:
-
Object
- Object
- SourceRoute::Wrapper
- Extended by:
- Forwardable
- Includes:
- Singleton
- Defined in:
- lib/source_route/wrapper.rb
Defined Under Namespace
Classes: Condition
Constant Summary collapse
- TRACE_POINT_METHODS =
[:defined_class, :method_id, :path, :lineno]
Instance Attribute Summary collapse
-
#condition ⇒ Object
Returns the value of attribute condition.
-
#tp ⇒ Object
Returns the value of attribute tp.
-
#tp_result_chain ⇒ Object
readonly
Returns the value of attribute tp_result_chain.
-
#tp_self_caches ⇒ Object
readonly
Returns the value of attribute tp_self_caches.
Instance Method Summary collapse
-
#initialize ⇒ Wrapper
constructor
A new instance of Wrapper.
- #jsonify_events ⇒ Object
- #jsonify_tp_result_chain ⇒ Object
- #jsonify_tp_self_caches ⇒ Object
- #reset ⇒ Object
- #stringify_tp_result_chain ⇒ Object
-
#stringify_tp_self_caches ⇒ Object
TODO: move this into chain self.
- #trace ⇒ Object
Constructor Details
#initialize ⇒ Wrapper
Returns a new instance of Wrapper.
58 59 60 |
# File 'lib/source_route/wrapper.rb', line 58 def initialize reset end |
Instance Attribute Details
#condition ⇒ Object
Returns the value of attribute condition.
8 9 10 |
# File 'lib/source_route/wrapper.rb', line 8 def condition @condition end |
#tp ⇒ Object
Returns the value of attribute tp.
8 9 10 |
# File 'lib/source_route/wrapper.rb', line 8 def tp @tp end |
#tp_result_chain ⇒ Object (readonly)
Returns the value of attribute tp_result_chain.
9 10 11 |
# File 'lib/source_route/wrapper.rb', line 9 def tp_result_chain @tp_result_chain end |
#tp_self_caches ⇒ Object (readonly)
Returns the value of attribute tp_self_caches.
9 10 11 |
# File 'lib/source_route/wrapper.rb', line 9 def tp_self_caches @tp_self_caches end |
Instance Method Details
#jsonify_events ⇒ Object
114 115 116 |
# File 'lib/source_route/wrapper.rb', line 114 def jsonify_events JSON.dump(@condition.events.map(&:to_s)) end |
#jsonify_tp_result_chain ⇒ Object
118 119 120 |
# File 'lib/source_route/wrapper.rb', line 118 def jsonify_tp_result_chain JSON.dump(stringify_tp_result_chain) end |
#jsonify_tp_self_caches ⇒ Object
122 123 124 |
# File 'lib/source_route/wrapper.rb', line 122 def jsonify_tp_self_caches JSON.dump(stringify_tp_self_caches) end |
#reset ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/source_route/wrapper.rb', line 62 def reset @tp.disable if defined? @tp @condition = Condition.new @tp_result_chain = TpResultChain.new @tp_self_caches = [] self end |
#stringify_tp_result_chain ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/source_route/wrapper.rb', line 95 def stringify_tp_result_chain deep_cloned = tp_result_chain.map do |tp_result| tp_result.clone end 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.key?(:defined_class) if tr.key?(:return_value) if tr[:return_value].nil? or tr[:return_value] == '' tr[:return_value] = tr[:return_value].inspect else tr[:return_value] = tr[:return_value].to_s end end tr end end |
#stringify_tp_self_caches ⇒ Object
TODO: move this into chain self
91 92 93 |
# File 'lib/source_route/wrapper.rb', line 91 def stringify_tp_self_caches tp_self_caches.clone.map(&:to_s) end |
#trace ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/source_route/wrapper.rb', line 70 def trace # dont wanna init it in tp block, cause tp block could run thousands of times in one cycle trace tp_result = GenerateResult.new(self) tp_filter = TpFilter.new(condition) track = TracePoint.new *condition.events do |tp| next if tp_filter.block_it?(tp) unless condition.result_config.format.is_a? Proc ret_data = tp_result.build(tp) @tp_result_chain.push(ret_data) end tp_result.output(tp) end track.enable self.tp = track end |