Class: Contracts::Runtime
Overview
–
- Author
-
radiospiel ([email protected])
- Copyright
-
Copyright © 2011, 2012 radiospiel
- License
-
Distributes under the terms of the Modified BSD License, see LICENSE.BSD for details.
++
Instance Attribute Summary collapse
-
#expected_runtime ⇒ Object
readonly
Returns the value of attribute expected_runtime.
-
#max ⇒ Object
readonly
Returns the value of attribute max.
Attributes inherited from Base
Instance Method Summary collapse
- #after_call(starts_at, _rv, _receiver, *_args, &_blk) ⇒ Object
- #before_call(_receiver, *_args, &_blk) ⇒ Object
-
#initialize(expected_runtime, options) ⇒ Runtime
constructor
A new instance of Runtime.
- #logger ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(expected_runtime, options) ⇒ Runtime
Returns a new instance of Runtime.
11 12 13 14 15 16 |
# File 'lib/contracts/runtime.rb', line 11 def initialize(expected_runtime, ) @expected_runtime = expected_runtime @max = [:max] expect! max.nil? || expected_runtime <= max end |
Instance Attribute Details
#expected_runtime ⇒ Object (readonly)
Returns the value of attribute expected_runtime.
9 10 11 |
# File 'lib/contracts/runtime.rb', line 9 def expected_runtime @expected_runtime end |
#max ⇒ Object (readonly)
Returns the value of attribute max.
9 10 11 |
# File 'lib/contracts/runtime.rb', line 9 def max @max end |
Instance Method Details
#after_call(starts_at, _rv, _receiver, *_args, &_blk) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/contracts/runtime.rb', line 22 def after_call(starts_at, _rv, _receiver, *_args, &_blk) runtime = Time.now - starts_at if max && runtime >= max error! "#{method_name} took longer than allowed: %.02f secs > %.02f secs." % [runtime, expected_runtime] end if runtime >= expected_runtime Contracts.logger.warn "#{method_name} took longer than expected: %.02f secs > %.02f secs." % [runtime, expected_runtime] end end |
#before_call(_receiver, *_args, &_blk) ⇒ Object
18 19 20 |
# File 'lib/contracts/runtime.rb', line 18 def before_call(_receiver, *_args, &_blk) Time.now end |
#logger ⇒ Object
34 35 36 |
# File 'lib/contracts/runtime.rb', line 34 def logger self.class.logger end |