Sha256: 4e5e022fb58fca12082d3959e2e08f392274423fe76638a36c6a91f902f29a06

Contents?: true

Size: 846 Bytes

Versions: 4

Compression:

Stored size: 846 Bytes

Contents

# frozen_string_literal: true

module Dry
  module Effects
    module Providers
      class CurrentTime < Provider[:current_time]
        module TimeGenerators
          FixedTimeGenerator = lambda do
            time = ::Time.now
            lambda do |refresh: false, **|
              time = ::Time.now if refresh
              time
            end
          end

          RunningTime = -> ** { ::Time.now }
          RunningTimeGenerator = -> { RunningTime }

          IncrementingTimeGenerator = lambda do |initial, step|
            start = Undefined.default(initial) { ::Time.now }
            current = nil

            lambda do |**|
              if current.nil?
                current = start
              else
                current += step
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dry-effects-0.5.0 lib/dry/effects/providers/current_time/time_generators.rb
dry-effects-0.4.1 lib/dry/effects/providers/current_time/time_generators.rb
dry-effects-0.4.0 lib/dry/effects/providers/current_time/time_generators.rb
dry-effects-0.3.1 lib/dry/effects/providers/current_time/time_generators.rb