Sha256: 1bc7018a891c0c2bb66edad94f3567f971580c6309907cd309f7bce9b00b249d
Contents?: true
Size: 1.06 KB
Versions: 2
Compression:
Stored size: 1.06 KB
Contents
# frozen_string_literal: true require "dry/effects/effect" require "dry/effects/constructors" module Dry module Effects module Effects class CurrentTime < ::Module CurrentTime = Effect.new(type: :current_time) Constructors.register(:CurrentTime) do |**kwargs| if kwargs.empty? CurrentTime else CurrentTime.(**kwargs) end end 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
dry-effects-0.3.0 | lib/dry/effects/effects/current_time.rb |
dry-effects-0.2.0 | lib/dry/effects/effects/current_time.rb |