Sha256: c554726ecbec3233ae358ed24deefae854be6377a8addc8534c8018f2e5d485b

Contents?: true

Size: 878 Bytes

Versions: 2

Compression:

Stored size: 878 Bytes

Contents

# frozen_string_literal: true

require "dry/effects/provider"

module Dry
  module Effects
    module Providers
      class CurrentTime < Provider[:current_time]
        module TimeGenetators
          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

2 entries across 2 versions & 1 rubygems

Version Path
dry-effects-0.3.0 lib/dry/effects/providers/current_time/time_generators.rb
dry-effects-0.2.0 lib/dry/effects/providers/current_time/time_generators.rb