class Dry::Effects::Providers::Timestamp

Constants

Locate

Attributes

generator[R]

Public Instance Methods

call(*args) { || ... } click to toggle source

Yield the block with the handler installed

@api private

# File lib/dry/effects/providers/timestamp.rb, line 22
def call(*args)
  gen, options = value_with_options_from_args(args)
  @generator = build_generator(gen, **options)
  yield
end
locate() click to toggle source

Locate handler in the stack

@return [Provider] @api private

# File lib/dry/effects/providers/timestamp.rb, line 44
def locate
  self
end
timestamp(round_to: Undefined, **options) click to toggle source
# File lib/dry/effects/providers/timestamp.rb, line 28
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

Private Instance Methods

build_generator(generator, step: Undefined, initial: Undefined, overridable: false) click to toggle source

@return [Proc] time generator @api private

# File lib/dry/effects/providers/timestamp.rb, line 52
def build_generator(generator, step: Undefined, initial: Undefined, overridable: false)
  if overridable
    parent = ::Dry::Effects.yield(Locate) { nil }
  else
    parent = nil
  end

  if !parent.nil?
    -> **options { parent.timestamp(**options) }
  elsif !Undefined.equal?(generator)
    generator
  elsif !Undefined.equal?(step)
    IncrementingTimeGenerator.(initial, step)
  else
    RunningTimeGenerator.()
  end
end