Class: Desiru::Core::Trace

Inherits:
Object
  • Object
show all
Defined in:
lib/desiru/core/trace.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(module_name:, signature:, inputs: {}, outputs: {}, metadata: {}) ⇒ Trace

Returns a new instance of Trace.



8
9
10
11
12
13
14
15
# File 'lib/desiru/core/trace.rb', line 8

def initialize(module_name:, signature:, inputs: {}, outputs: {}, metadata: {})
  @module_name = module_name
  @signature = signature
  @inputs = inputs
  @outputs = outputs
   = 
  @timestamp = Time.now
end

Instance Attribute Details

#inputsObject (readonly)

Returns the value of attribute inputs.



6
7
8
# File 'lib/desiru/core/trace.rb', line 6

def inputs
  @inputs
end

#metadataObject (readonly)

Returns the value of attribute metadata.



6
7
8
# File 'lib/desiru/core/trace.rb', line 6

def 
  
end

#module_nameObject (readonly)

Returns the value of attribute module_name.



6
7
8
# File 'lib/desiru/core/trace.rb', line 6

def module_name
  @module_name
end

#outputsObject (readonly)

Returns the value of attribute outputs.



6
7
8
# File 'lib/desiru/core/trace.rb', line 6

def outputs
  @outputs
end

#signatureObject (readonly)

Returns the value of attribute signature.



6
7
8
# File 'lib/desiru/core/trace.rb', line 6

def signature
  @signature
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



6
7
8
# File 'lib/desiru/core/trace.rb', line 6

def timestamp
  @timestamp
end

Instance Method Details

#==(other) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/desiru/core/trace.rb', line 54

def ==(other)
  return false unless other.is_a?(self.class)

  @module_name == other.module_name &&
    @signature == other.signature &&
    @inputs == other.inputs &&
    @outputs == other.outputs &&
     == other.
end

#durationObject



44
45
46
# File 'lib/desiru/core/trace.rb', line 44

def duration
  [:duration]
end

#duration_msObject



48
49
50
51
52
# File 'lib/desiru/core/trace.rb', line 48

def duration_ms
  return 0 unless duration

  (duration * 1000).to_f
end

#errorObject



40
41
42
# File 'lib/desiru/core/trace.rb', line 40

def error
  [:error]
end

#error?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/desiru/core/trace.rb', line 36

def error?
  .key?(:error)
end

#success?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/desiru/core/trace.rb', line 32

def success?
  [:success] != false
end

#to_exampleObject



28
29
30
# File 'lib/desiru/core/trace.rb', line 28

def to_example
  Example.new(**@inputs, **@outputs)
end

#to_hObject



17
18
19
20
21
22
23
24
25
26
# File 'lib/desiru/core/trace.rb', line 17

def to_h
  {
    module_name: @module_name,
    signature: @signature.is_a?(String) ? @signature : @signature.to_h,
    inputs: @inputs,
    outputs: @outputs,
    metadata: ,
    timestamp: @timestamp
  }
end