Class: Stratagem::Instrumentation::MethodInvocation

Inherits:
Object
  • Object
show all
Defined in:
lib/stratagem/instrumentation/method_invocation.rb

Constant Summary collapse

EQUALITY_ATTRS =
[:method, :controller_path, :controller_action, :line_number, :model_class]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ MethodInvocation

TODO - refactor, ugly constructor is a result of quick port from Struct



8
9
10
11
12
13
14
# File 'lib/stratagem/instrumentation/method_invocation.rb', line 8

def initialize(*args)
  arg_keys = [:method, :controller_path, :controller_action, :line_number, :model_instance, :model_class, :stack_trace, :args, :type]
  args.each_with_index do |val,i|
    self.send("#{arg_keys[i].to_s}=", val)
  end
  self.controller_path = controller_path.gsub(/.*?\/app/, 'app') if controller_path
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



3
4
5
# File 'lib/stratagem/instrumentation/method_invocation.rb', line 3

def args
  @args
end

#controller_actionObject

Returns the value of attribute controller_action.



3
4
5
# File 'lib/stratagem/instrumentation/method_invocation.rb', line 3

def controller_action
  @controller_action
end

#controller_pathObject

Returns the value of attribute controller_path.



3
4
5
# File 'lib/stratagem/instrumentation/method_invocation.rb', line 3

def controller_path
  @controller_path
end

#line_numberObject

Returns the value of attribute line_number.



3
4
5
# File 'lib/stratagem/instrumentation/method_invocation.rb', line 3

def line_number
  @line_number
end

#methodObject

Returns the value of attribute method.



3
4
5
# File 'lib/stratagem/instrumentation/method_invocation.rb', line 3

def method
  @method
end

#model_classObject

Returns the value of attribute model_class.



3
4
5
# File 'lib/stratagem/instrumentation/method_invocation.rb', line 3

def model_class
  @model_class
end

#model_instanceObject

Returns the value of attribute model_instance.



3
4
5
# File 'lib/stratagem/instrumentation/method_invocation.rb', line 3

def model_instance
  @model_instance
end

#stack_traceObject

Returns the value of attribute stack_trace.



3
4
5
# File 'lib/stratagem/instrumentation/method_invocation.rb', line 3

def stack_trace
  @stack_trace
end

#typeObject

Returns the value of attribute type.



3
4
5
# File 'lib/stratagem/instrumentation/method_invocation.rb', line 3

def type
  @type
end

Instance Method Details

#<=>(other) ⇒ Object



16
17
18
19
# File 'lib/stratagem/instrumentation/method_invocation.rb', line 16

def <=>(other)
  e = self.==(other)
  e ? 0 : 1
end

#==(other) ⇒ Object



21
22
23
# File 'lib/stratagem/instrumentation/method_invocation.rb', line 21

def ==(other)
  eql?(other)
end

#controllerObject



32
33
34
35
# File 'lib/stratagem/instrumentation/method_invocation.rb', line 32

def controller
  app = Stratagem::Model::Application.instance
  controller = controller_path ? app.controllers.find {|controller| controller.path == controller_path } : nil
end

#eql?(other) ⇒ Boolean

override so that uniq works properly

Returns:

  • (Boolean)


26
27
28
29
30
# File 'lib/stratagem/instrumentation/method_invocation.rb', line 26

def eql?(other)
  EQUALITY_ATTRS.find {|key|
    (self.send(key) != other.send(key))
  }.nil?
end

#modelObject



37
38
39
40
# File 'lib/stratagem/instrumentation/method_invocation.rb', line 37

def model
  app = Stratagem::Model::Application.instance
  model = model_class ? app.models.find {|model| model.klass.name == model_class.name } : nil
end


54
55
56
# File 'lib/stratagem/instrumentation/method_invocation.rb', line 54

def print
  puts "#{controller_path}.#{controller_action}:#{line_number} -> #{model_class.name}.#{method}"
end

#to_referenceObject



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/stratagem/instrumentation/method_invocation.rb', line 42

def to_reference
  Stratagem::Model::Component::Reference.new(
    :from_component => controller,
    :to_component => model,
    :function => controller_action,
    :request_method => method, 
    :line_number => line_number,
    :reference_type => type,
    :stack_trace => stack_trace
  )
end