Sha256: af71a5c4a714c9520ad595a8129322569c26b21a2677e76c09db49be45a67359

Contents?: true

Size: 1.27 KB

Versions: 82

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

module ActiveModel
  module Type
    module Helpers # :nodoc: all
      class AcceptsMultiparameterTime < Module
        module InstanceMethods
          def serialize(value)
            super(cast(value))
          end

          def cast(value)
            if value.is_a?(Hash)
              value_from_multiparameter_assignment(value)
            else
              super(value)
            end
          end

          def assert_valid_value(value)
            if value.is_a?(Hash)
              value_from_multiparameter_assignment(value)
            else
              super(value)
            end
          end

          def value_constructed_by_mass_assignment?(value)
            value.is_a?(Hash)
          end
        end

        def initialize(defaults: {})
          include InstanceMethods

          define_method(:value_from_multiparameter_assignment) do |values_hash|
            defaults.each do |k, v|
              values_hash[k] ||= v
            end
            return unless values_hash[1] && values_hash[2] && values_hash[3]
            values = values_hash.sort.map!(&:last)
            ::Time.public_send(default_timezone, *values)
          end
          private :value_from_multiparameter_assignment
        end
      end
    end
  end
end

Version data entries

82 entries across 78 versions & 9 rubygems

Version Path
activemodel-7.0.8.6 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-6.1.7.10 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-6.1.7.9 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-7.0.8.5 lib/active_model/type/helpers/accepts_multiparameter_time.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/activemodel-7.0.8.4/lib/active_model/type/helpers/accepts_multiparameter_time.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/activemodel-7.0.5.1/lib/active_model/type/helpers/accepts_multiparameter_time.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/activemodel-7.0.5.1/lib/active_model/type/helpers/accepts_multiparameter_time.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/activemodel-7.0.5.1/lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-7.0.8.4 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-6.1.7.8 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-7.0.8.1 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-6.1.7.7 lib/active_model/type/helpers/accepts_multiparameter_time.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activemodel-7.0.3.1/lib/active_model/type/helpers/accepts_multiparameter_time.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activemodel-7.0.2.3/lib/active_model/type/helpers/accepts_multiparameter_time.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activemodel-6.1.6.1/lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-7.0.8 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-7.0.7.2 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-6.1.7.6 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-7.0.7.1 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-6.1.7.5 lib/active_model/type/helpers/accepts_multiparameter_time.rb