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



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

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

Instance Attribute Details

#elapsedr (readonly)

Returns elapsed @return [Float] The time elapsed for this interceptor to execute.

Returns:

  • (r)

    elapsed @return [Float] The time elapsed for this interceptor to execute



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

def elapsed
  @elapsed
end

#messageObject (readonly)

Returns the value of attribute message.



33
34
35
# File 'lib/gruf/interceptors/timer.rb', line 33

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



69
70
71
# File 'lib/gruf/interceptors/timer.rb', line 69

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



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

def message_class_name
  @message.class.name.to_s
end

#successful?Boolean

Returns True if this was a successful request.

Returns:

  • (Boolean)

    True if this was a successful request



52
53
54
# File 'lib/gruf/interceptors/timer.rb', line 52

def successful?
  @successful
end