Sha256: c84a460437a736632ba129207a8c0c13bc372249d2c7c9bc391c8e25269190a9

Contents?: true

Size: 1.16 KB

Versions: 40

Compression:

Stored size: 1.16 KB

Contents

# frozen_string_literal: true

module ActiveModel
  module Type
    module Helpers # :nodoc: all
      class AcceptsMultiparameterTime < Module
        def initialize(defaults: {})
          define_method(:cast) do |value|
            if value.is_a?(Hash)
              value_from_multiparameter_assignment(value)
            else
              super(value)
            end
          end

          define_method(:assert_valid_value) do |value|
            if value.is_a?(Hash)
              value_from_multiparameter_assignment(value)
            else
              super(value)
            end
          end

          define_method(:value_constructed_by_mass_assignment?) do |value|
            value.is_a?(Hash)
          end

          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.send(default_timezone, *values)
          end
          private :value_from_multiparameter_assignment
        end
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 6 rubygems

Version Path
activemodel-5.2.8.1 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.2.8 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.2.7.1 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.2.7 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.2.6.3 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.2.6.2 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.2.6.1 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.2.6 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.2.4.6 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.2.5 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.2.4.5 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.2.4.4 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.2.4.3 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.2.4.2 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.2.4.1 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.2.4 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.2.4.rc1 lib/active_model/type/helpers/accepts_multiparameter_time.rb
spiral_form-0.1.1 vendor/bundle/gems/activemodel-5.2.3/lib/active_model/type/helpers/accepts_multiparameter_time.rb
spiral_form-0.1.0 vendor/bundle/gems/activemodel-5.2.3/lib/active_model/type/helpers/accepts_multiparameter_time.rb
ric-0.13.0 vendor/bundle/ruby/2.5.0/gems/activemodel-5.2.3/lib/active_model/type/helpers/accepts_multiparameter_time.rb