Class: Dry::Effects::Providers::CurrentTime

Inherits:
Object
  • Object
show all
Includes:
TimeGenerators
Defined in:
lib/dry/effects/providers/current_time.rb,
lib/dry/effects/providers/current_time/time_generators.rb

Defined Under Namespace

Modules: TimeGenerators

Constant Summary collapse

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

Constants included from TimeGenerators

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#generatorObject (readonly)

Returns the value of attribute generator.



20
21
22
# File 'lib/dry/effects/providers/current_time.rb', line 20

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



25
26
27
28
29
# File 'lib/dry/effects/providers/current_time.rb', line 25

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

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



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/dry/effects/providers/current_time.rb', line 31

def current_time(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

#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:



47
48
49
# File 'lib/dry/effects/providers/current_time.rb', line 47

def locate
  self
end

#representString

Returns:

  • (String)


53
54
55
56
57
58
59
60
61
62
63
# File 'lib/dry/effects/providers/current_time.rb', line 53

def represent
  if fixed?
    if generator.nil?
      "current_time[fixed=true]"
    else
      "current_time[fixed=#{generator.().iso8601(6)}]"
    end
  else
    "current_time[fixed=false]"
  end
end