Class: Dry::Effects::Providers::Timestamp

Inherits:
Object
  • Object
show all
Includes:
CurrentTime::TimeGenerators
Defined in:
lib/dry/effects/providers/timestamp.rb

Constant Summary collapse

Locate =
Effect.new(type: :timestamp, name: :locate)

Constants included from CurrentTime::TimeGenerators

CurrentTime::TimeGenerators::FixedTimeGenerator, CurrentTime::TimeGenerators::IncrementingTimeGenerator, CurrentTime::TimeGenerators::RunningTime, CurrentTime::TimeGenerators::RunningTimeGenerator

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#generatorObject (readonly)

Returns the value of attribute generator.



14
15
16
# File 'lib/dry/effects/providers/timestamp.rb', line 14

def generator
  @generator
end

Instance Method Details

#call(*args) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Yield the block with the handler installed



19
20
21
22
23
# File 'lib/dry/effects/providers/timestamp.rb', line 19

def call(*args)
  gen, options = value_with_options_from_args(args)
  @generator = build_generator(gen, **options)
  yield
end

#locateProvider

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Locate handler in the stack

Returns:



41
42
43
# File 'lib/dry/effects/providers/timestamp.rb', line 41

def locate
  self
end

#timestamp(round_to: Undefined, **options) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/dry/effects/providers/timestamp.rb', line 25

def timestamp(round_to: Undefined, **options)
  time = generator.(**options)

  round = Undefined.coalesce(round_to, self.round)

  if Undefined.equal?(round)
    time
  else
    time.round(round)
  end
end