Sha256: 0505de4caf08655ab2abf198c17359810660f6c8216edf9e2398aee0c4f18aa9

Contents?: true

Size: 833 Bytes

Versions: 4

Compression:

Stored size: 833 Bytes

Contents

# frozen_string_literal: true

module Dry
  module Effects
    module Effects
      class CurrentTime < ::Module
        CurrentTime = Effect.new(type: :current_time)

        def initialize(**options)
          super()

          module_eval do
            define_method(:current_time) do |opts = EMPTY_HASH|
              round = opts.fetch(:round, Undefined)
              refresh = opts.fetch(:refresh, false)
              round_to = Undefined.coalesce(round, options.fetch(:round, Undefined))

              if Undefined.equal?(round_to) && refresh.equal?(false)
                effect = CurrentTime
              else
                effect = CurrentTime.(round_to: round_to, refresh: refresh)
              end

              ::Dry::Effects.yield(effect)
            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/effects/current_time.rb
dry-effects-0.4.1 lib/dry/effects/effects/current_time.rb
dry-effects-0.4.0 lib/dry/effects/effects/current_time.rb
dry-effects-0.3.1 lib/dry/effects/effects/current_time.rb