Class: GunDog::CallRecord

Inherits:
Object
  • Object
show all
Defined in:
lib/gun_dog/call_record.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, method_name, class_method: false, generated: false) ⇒ CallRecord

Returns a new instance of CallRecord.



29
30
31
32
33
34
# File 'lib/gun_dog/call_record.rb', line 29

def initialize(klass, method_name, class_method: false, generated: false)
  @klass = klass
  @method_name = method_name
  @class_method = class_method
  @generated = generated
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



5
6
7
# File 'lib/gun_dog/call_record.rb', line 5

def args
  @args
end

#cyclical=(value) ⇒ Object (writeonly)

Sets the attribute cyclical

Parameters:

  • value

    the value to set the attribute cyclical to.



8
9
10
# File 'lib/gun_dog/call_record.rb', line 8

def cyclical=(value)
  @cyclical = value
end

#dynamic=(value) ⇒ Object (writeonly)

Sets the attribute dynamic

Parameters:

  • value

    the value to set the attribute dynamic to.



8
9
10
# File 'lib/gun_dog/call_record.rb', line 8

def dynamic=(value)
  @dynamic = value
end

#internal=(value) ⇒ Object (writeonly)

Sets the attribute internal

Parameters:

  • value

    the value to set the attribute internal to.



8
9
10
# File 'lib/gun_dog/call_record.rb', line 8

def internal=(value)
  @internal = value
end

#method_nameObject

Returns the value of attribute method_name.



5
6
7
# File 'lib/gun_dog/call_record.rb', line 5

def method_name
  @method_name
end

#return_valueObject

Returns the value of attribute return_value.



5
6
7
# File 'lib/gun_dog/call_record.rb', line 5

def return_value
  @return_value
end

#stackObject

Returns the value of attribute stack.



6
7
8
# File 'lib/gun_dog/call_record.rb', line 6

def stack
  @stack
end

Class Method Details

.from_json(json) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/gun_dog/call_record.rb', line 10

def self.from_json(json)
  cr = new(
    Utilities.get_class(json['klass']),
    json['method_name'],
    class_method: json['class_method'],
    generated: json['generated']
  )

  cr.instance_eval do
    @internal = json['internal']
    @cyclical = json['cyclical']
    @args = json['args']
    @return_value = json['return_value']
    @stack = TraceStack.from_array(klass: @klass, stack: json['stack']) if json['stack']
  end

  cr
end

Instance Method Details

#as_jsonObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/gun_dog/call_record.rb', line 76

def as_json
  {
    "klass" => @klass.json_encoded,
    "method_name" => method_name.to_s,
    "class_method" => class_method?,
    "generated" => generated?,
    "internal" => internal?,
    "cyclical" => cyclical?,
    "dynamic" => dynamic?,
    "args" => args.each_pair.with_object({}) { |(k,v), memo| memo[k.to_s] = v},
    "return_value" => return_value,
    "stack" => stack&.as_json
  }.reject { |_,v| v.nil? }
end

#call_record_signatureObject



68
69
70
71
72
73
74
# File 'lib/gun_dog/call_record.rb', line 68

def call_record_signature
  "#{generated? ? "[generated] " : nil } \
    def #{class_method? ? "self." : nil}#{method_name}(#{type_signatures(args)}) : #{return_value.class} \
    #{ internal? ? " (internal)" : nil } \
    #{ cyclical? ? " (cyclical)" : nil } \
    #{ dynamic? ? " (dynamic)" : nil }".squish
end

#class_method?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/gun_dog/call_record.rb', line 52

def class_method?
  !!@class_method
end

#cyclical?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/gun_dog/call_record.rb', line 44

def cyclical?
  !!@cyclical
end

#dynamic?Boolean

Returns:

  • (Boolean)


48
49
50
# File 'lib/gun_dog/call_record.rb', line 48

def dynamic?
  !!@dynamic
end

#generated?Boolean

Returns:

  • (Boolean)


56
57
58
# File 'lib/gun_dog/call_record.rb', line 56

def generated?
  !!@generated
end

#internal?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/gun_dog/call_record.rb', line 40

def internal?
  !!@internal
end

#method_locationObject



36
37
38
# File 'lib/gun_dog/call_record.rb', line 36

def method_location
  "#{@klass}#{method_separator}#{method_name}"
end

#unbound_methodObject



60
61
62
63
64
65
66
# File 'lib/gun_dog/call_record.rb', line 60

def unbound_method
  if class_method?
    @klass.method(method_name).unbind
  else
    @klass.instance_method(method_name)
  end
end