class Dry::Effects::Providers::CurrentTime
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/current_time.rb, line 27 def call(*args) gen, options = value_with_options_from_args(args) @generator = build_generator(gen, **options) yield end
current_time(round_to: Undefined, **options)
click to toggle source
# File lib/dry/effects/providers/current_time.rb, line 33 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
locate()
click to toggle source
Locate
handler in the stack
@return [Provider] @api private
# File lib/dry/effects/providers/current_time.rb, line 49 def locate self end
represent()
click to toggle source
@return [String] @api public
# File lib/dry/effects/providers/current_time.rb, line 55 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
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/current_time.rb, line 71 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.current_time(**options) } elsif !Undefined.equal?(generator) generator elsif !Undefined.equal?(step) IncrementingTimeGenerator.(initial, step) elsif fixed? FixedTimeGenerator.() else RunningTimeGenerator.() end end