Class: SourceRoute::Wrapper
- Inherits:
-
Object
- Object
- SourceRoute::Wrapper
- Includes:
- Singleton
- Defined in:
- lib/source_route/wrapper.rb
Constant Summary collapse
- TRACE_POINT_METHODS =
[:defined_class, :method_id, :path, :lineno]
Instance Attribute Summary collapse
-
#conditions ⇒ Object
Returns the value of attribute conditions.
-
#output_include_instance_variables ⇒ Object
Returns the value of attribute output_include_instance_variables.
-
#output_include_local_variables ⇒ Object
Returns the value of attribute output_include_local_variables.
-
#tp ⇒ Object
Returns the value of attribute tp.
-
#tp_attrs_results ⇒ Object
Returns the value of attribute tp_attrs_results.
Instance Method Summary collapse
- #events(v) ⇒ Object (also: #event)
-
#initialize ⇒ Wrapper
constructor
A new instance of Wrapper.
- #output_format(data = nil, &block) ⇒ Object
-
#reset ⇒ Object
output_format can be console, html.
- #selected_attrs(*attr) ⇒ Object
- #set_result_config(value) ⇒ Object
- #trace ⇒ Object
Constructor Details
#initialize ⇒ Wrapper
Returns a new instance of Wrapper.
9 10 11 |
# File 'lib/source_route/wrapper.rb', line 9 def initialize reset end |
Instance Attribute Details
#conditions ⇒ Object
Returns the value of attribute conditions.
6 7 8 |
# File 'lib/source_route/wrapper.rb', line 6 def conditions @conditions end |
#output_include_instance_variables ⇒ Object
Returns the value of attribute output_include_instance_variables.
7 8 9 |
# File 'lib/source_route/wrapper.rb', line 7 def output_include_instance_variables @output_include_instance_variables end |
#output_include_local_variables ⇒ Object
Returns the value of attribute output_include_local_variables.
7 8 9 |
# File 'lib/source_route/wrapper.rb', line 7 def output_include_local_variables @output_include_local_variables end |
#tp ⇒ Object
Returns the value of attribute tp.
6 7 8 |
# File 'lib/source_route/wrapper.rb', line 6 def tp @tp end |
#tp_attrs_results ⇒ Object
Returns the value of attribute tp_attrs_results.
6 7 8 |
# File 'lib/source_route/wrapper.rb', line 6 def tp_attrs_results @tp_attrs_results end |
Instance Method Details
#events(v) ⇒ Object Also known as: event
26 27 28 |
# File 'lib/source_route/wrapper.rb', line 26 def events(v) @conditions.events = Array(v).map(&:to_sym) unless v.nil? end |
#output_format(data = nil, &block) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/source_route/wrapper.rb', line 37 def output_format(data = nil, &block) conditions.result_config[:output_format] = if block_given? block else data end end |
#reset ⇒ Object
output_format can be console, html
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/source_route/wrapper.rb', line 14 def reset @tp.disable if @tp @conditions = OpenStruct.new(events: [:call], negative: {}, positive: {}, result_config: { output_format: 'none', selected_attrs: nil, include_local_var: false, include_instance_var: false }) @tp_attrs_results = [] self end |
#selected_attrs(*attr) ⇒ Object
45 46 47 |
# File 'lib/source_route/wrapper.rb', line 45 def selected_attrs(*attr) conditions.result_config[:selected_attrs] = Array(attr) end |
#set_result_config(value) ⇒ Object
31 32 33 34 35 |
# File 'lib/source_route/wrapper.rb', line 31 def set_result_config(value) unless value.is_a? Hash conditions.result_config = value end end |
#trace ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/source_route/wrapper.rb', line 69 def trace # dont wanna init it in tp block, cause tp block could run thousands of time in one cycle trace tp_result = TpResult.new(self) track = TracePoint.new *conditions.events do |tp| negative_break = conditions.negative.any? do |method_key, value| tp.send(method_key).nature_value =~ Regexp.new(value) end next if negative_break positive_break = conditions.positive.any? do |method_key, value| tp.send(method_key).nature_value !~ Regexp.new(value) end next if positive_break unless conditions[:result_config][:output_format].is_a? Proc ret_data = tp_result.build(tp) tp_attrs_results.push(ret_data) end tp_result.output(tp) end track.enable self.tp = track track end |