Class: Trace2::ClassUse
- Inherits:
-
Object
- Object
- Trace2::ClassUse
- Defined in:
- lib/trace2/class_use.rb
Overview
Registers how a class was used during run time
Instance Attribute Summary collapse
-
#callees ⇒ Object
readonly
Returns the value of attribute callees.
-
#caller_class ⇒ Object
Returns the value of attribute caller_class.
-
#event ⇒ Object
readonly
Returns the value of attribute event.
-
#line ⇒ Object
readonly
Returns the value of attribute line.
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#stack_level ⇒ Object
readonly
Returns the value of attribute stack_level.
Instance Method Summary collapse
- #add_callee(callee) ⇒ Object
- #callers_stack(options = {}) ⇒ Object
-
#initialize(params) ⇒ ClassUse
constructor
A new instance of ClassUse.
- #matches_bottom_of_stack?(is_bottom) ⇒ Boolean
- #matches_caller_class?(caller_attributes) ⇒ Boolean
- #matches_method?(methods_names) ⇒ Boolean
- #matches_name?(classes_names) ⇒ Boolean
- #matches_path?(paths_patterns) ⇒ Boolean
- #matches_top_of_stack?(is_top) ⇒ Boolean
Constructor Details
#initialize(params) ⇒ ClassUse
Returns a new instance of ClassUse.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/trace2/class_use.rb', line 9 def initialize(params) @name = params[:name] @method = params[:method] @caller_class = params[:caller_class] @stack_level = params[:stack_level] @path = params[:path] @line = params[:line] @callees = params[:callees] || [] @event = params[:event] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object (private)
97 98 99 100 101 |
# File 'lib/trace2/class_use.rb', line 97 def method_missing(method, *args, &block) return true if respond_to_missing?(method, args) super end |
Instance Attribute Details
#callees ⇒ Object (readonly)
Returns the value of attribute callees.
6 7 8 |
# File 'lib/trace2/class_use.rb', line 6 def callees @callees end |
#caller_class ⇒ Object
Returns the value of attribute caller_class.
7 8 9 |
# File 'lib/trace2/class_use.rb', line 7 def caller_class @caller_class end |
#event ⇒ Object (readonly)
Returns the value of attribute event.
6 7 8 |
# File 'lib/trace2/class_use.rb', line 6 def event @event end |
#line ⇒ Object (readonly)
Returns the value of attribute line.
6 7 8 |
# File 'lib/trace2/class_use.rb', line 6 def line @line end |
#method ⇒ Object (readonly)
Returns the value of attribute method.
6 7 8 |
# File 'lib/trace2/class_use.rb', line 6 def method @method end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/trace2/class_use.rb', line 6 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/trace2/class_use.rb', line 6 def path @path end |
#stack_level ⇒ Object (readonly)
Returns the value of attribute stack_level.
6 7 8 |
# File 'lib/trace2/class_use.rb', line 6 def stack_level @stack_level end |
Instance Method Details
#add_callee(callee) ⇒ Object
57 58 59 |
# File 'lib/trace2/class_use.rb', line 57 def add_callee(callee) callees << callee end |
#callers_stack(options = {}) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/trace2/class_use.rb', line 20 def callers_stack( = {}) curr_class = caller_class callers_stack = [] until curr_class.nil? curr_caller = (curr_class, ) callers_stack.push(curr_caller) unless curr_caller.nil? curr_class = curr_class.caller_class end callers_stack end |
#matches_bottom_of_stack?(is_bottom) ⇒ Boolean
43 44 45 |
# File 'lib/trace2/class_use.rb', line 43 def matches_bottom_of_stack?(is_bottom) caller_class.nil? == is_bottom end |
#matches_caller_class?(caller_attributes) ⇒ Boolean
51 52 53 54 55 |
# File 'lib/trace2/class_use.rb', line 51 def matches_caller_class?(caller_attributes) callers_stack.any? do |current_caller| valid_caller?(current_caller, caller_attributes) end end |
#matches_method?(methods_names) ⇒ Boolean
31 32 33 |
# File 'lib/trace2/class_use.rb', line 31 def matches_method?(methods_names) methods_names.any? { |method_name| method.match(method_name) } end |
#matches_name?(classes_names) ⇒ Boolean
35 36 37 |
# File 'lib/trace2/class_use.rb', line 35 def matches_name?(classes_names) classes_names.any? { |class_name| name.match(class_name) } end |
#matches_path?(paths_patterns) ⇒ Boolean
39 40 41 |
# File 'lib/trace2/class_use.rb', line 39 def matches_path?(paths_patterns) paths_patterns.any? { |path_pattern| path.match(path_pattern) } end |
#matches_top_of_stack?(is_top) ⇒ Boolean
47 48 49 |
# File 'lib/trace2/class_use.rb', line 47 def matches_top_of_stack?(is_top) callees.empty? == is_top end |