Sha256: 2c76af195b67cbdcc6c7931e996af909d6633ece9741717017968d861cdb90f1

Contents?: true

Size: 702 Bytes

Versions: 2

Compression:

Stored size: 702 Bytes

Contents

# frozen_string_literal: true

require "dry/effects/effect"

module Dry
  module Effects
    module Effects
      class Timestamp < ::Module
        Timestamp = Effect.new(type: :timestamp)

        def initialize(options = EMPTY_HASH)
          super()

          module_eval do
            define_method(:timestamp) do |round: Undefined|
              round_to = Undefined.coalesce(round, options.fetch(:round, Undefined))

              if Undefined.equal?(round_to)
                ::Dry::Effects.yield(Timestamp)
              else
                ::Dry::Effects.yield(Timestamp.keywords(round_to: round_to))
              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/effects/timestamp.rb
dry-effects-0.2.0 lib/dry/effects/effects/timestamp.rb