Class: Gruf::Interceptors::Timer::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/gruf/interceptors/timer.rb

Overview

Represents a timed result for an interceptor

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, elapsed, successful) ⇒ Result

Returns a new instance of Result.

Parameters:

  • message (Object)

    The protobuf message

  • elapsed (Float)

    The elapsed time of the request

  • successful (Boolean)

    If the request was successful



39
40
41
42
43
# File 'lib/gruf/interceptors/timer.rb', line 39

def initialize(message, elapsed, successful)
  @message = message
  @elapsed = elapsed.to_f
  @successful = successful ? true : false
end

Instance Attribute Details

#elapsedObject (readonly)

Returns the value of attribute elapsed.



31
32
33
# File 'lib/gruf/interceptors/timer.rb', line 31

def elapsed
  @elapsed
end

#messageObject (readonly)

Returns the value of attribute message.



31
32
33
# File 'lib/gruf/interceptors/timer.rb', line 31

def message
  @message
end

Instance Method Details

#elapsed_rounded(precision: 2) ⇒ Float

Return the execution time rounded to a specified precision

Parameters:

  • precision (Integer) (defaults to: 2)

    The amount of decimal places to round to

Returns:

  • (Float)

    The execution time rounded to the appropriate decimal point



65
66
67
# File 'lib/gruf/interceptors/timer.rb', line 65

def elapsed_rounded(precision: 2)
  @elapsed.to_f.round(precision)
end

#message_class_nameString

Returns The name of the message class.

Returns:

  • (String)

    The name of the message class



55
56
57
# File 'lib/gruf/interceptors/timer.rb', line 55

def message_class_name
  @message.class.name
end

#successful?Boolean

Returns True if this was a successful request.

Returns:

  • (Boolean)

    True if this was a successful request



48
49
50
# File 'lib/gruf/interceptors/timer.rb', line 48

def successful?
  @successful
end