Class: Kitsune::Kit::Adapters::FakeClock
- Defined in:
- lib/kitsune/kit/adapters/fake_clock.rb
Instance Attribute Summary collapse
-
#monotonic ⇒ Object
readonly
Returns the value of attribute monotonic.
-
#now ⇒ Object
readonly
Returns the value of attribute now.
-
#sleeps ⇒ Object
readonly
Returns the value of attribute sleeps.
Instance Method Summary collapse
- #advance(seconds) ⇒ Object
-
#initialize(now: Time.utc(2026, 1, 1), monotonic: 0.0) ⇒ FakeClock
constructor
A new instance of FakeClock.
- #sleep(seconds) ⇒ Object
Constructor Details
#initialize(now: Time.utc(2026, 1, 1), monotonic: 0.0) ⇒ FakeClock
Returns a new instance of FakeClock.
11 12 13 14 15 16 |
# File 'lib/kitsune/kit/adapters/fake_clock.rb', line 11 def initialize(now: Time.utc(2026, 1, 1), monotonic: 0.0) super() @now = now.utc @monotonic = Float(monotonic) @sleeps = [] end |
Instance Attribute Details
#monotonic ⇒ Object (readonly)
Returns the value of attribute monotonic.
9 10 11 |
# File 'lib/kitsune/kit/adapters/fake_clock.rb', line 9 def monotonic @monotonic end |
#now ⇒ Object (readonly)
Returns the value of attribute now.
9 10 11 |
# File 'lib/kitsune/kit/adapters/fake_clock.rb', line 9 def now @now end |
#sleeps ⇒ Object (readonly)
Returns the value of attribute sleeps.
9 10 11 |
# File 'lib/kitsune/kit/adapters/fake_clock.rb', line 9 def sleeps @sleeps end |
Instance Method Details
#advance(seconds) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/kitsune/kit/adapters/fake_clock.rb', line 25 def advance(seconds) seconds = Float(seconds) @now += seconds @monotonic += seconds self end |
#sleep(seconds) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/kitsune/kit/adapters/fake_clock.rb', line 18 def sleep(seconds) seconds = Float(seconds) @sleeps << seconds advance(seconds) seconds end |