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



34
35
36
37
38
# File 'lib/gruf/interceptors/timer.rb', line 34

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.



27
28
29
# File 'lib/gruf/interceptors/timer.rb', line 27

def elapsed
  @elapsed
end

#messageObject (readonly)

Returns the value of attribute message.



26
27
28
# File 'lib/gruf/interceptors/timer.rb', line 26

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



60
61
62
# File 'lib/gruf/interceptors/timer.rb', line 60

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



50
51
52
# File 'lib/gruf/interceptors/timer.rb', line 50

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



43
44
45
# File 'lib/gruf/interceptors/timer.rb', line 43

def successful?
  @successful
end