Class: Trace2::ClassUse

Inherits:
Object
  • Object
show all
Defined in:
lib/trace2/class_use.rb

Overview

Registers how a class was used during run time

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#calleesObject (readonly)

Returns the value of attribute callees.



6
7
8
# File 'lib/trace2/class_use.rb', line 6

def callees
  @callees
end

#caller_classObject

Returns the value of attribute caller_class.



7
8
9
# File 'lib/trace2/class_use.rb', line 7

def caller_class
  @caller_class
end

#eventObject (readonly)

Returns the value of attribute event.



6
7
8
# File 'lib/trace2/class_use.rb', line 6

def event
  @event
end

#lineObject (readonly)

Returns the value of attribute line.



6
7
8
# File 'lib/trace2/class_use.rb', line 6

def line
  @line
end

#methodObject (readonly)

Returns the value of attribute method.



6
7
8
# File 'lib/trace2/class_use.rb', line 6

def method
  @method
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/trace2/class_use.rb', line 6

def name
  @name
end

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/trace2/class_use.rb', line 6

def path
  @path
end

#stack_levelObject (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(options = {})
  curr_class = caller_class
  callers_stack = []
  until curr_class.nil?
    curr_caller = run_options(curr_class, options)
    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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (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

Returns:

  • (Boolean)


47
48
49
# File 'lib/trace2/class_use.rb', line 47

def matches_top_of_stack?(is_top)
  callees.empty? == is_top
end