Sha256: 2bdb7631dcc18c7adb2cdefc15b9a88603d4a1356d87efeb2541792aa827e4c4

Contents?: true

Size: 1.01 KB

Versions: 22

Compression:

Stored size: 1.01 KB

Contents

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_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

22 entries across 22 versions & 2 rubygems

Version Path
activemodel-5.1.7 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.1.7.rc1 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.1.6.2 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.1.6.1 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.1.6 lib/active_model/type/helpers/accepts_multiparameter_time.rb
tdiary-5.0.8 vendor/bundle/gems/activemodel-5.1.5/lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.1.5 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.1.5.rc1 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.1.4 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.1.4.rc1 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.1.3 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.1.3.rc3 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.1.3.rc2 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.1.3.rc1 lib/active_model/type/helpers/accepts_multiparameter_time.rb
tdiary-5.0.5 vendor/bundle/gems/activemodel-5.1.2/lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.1.2 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.1.2.rc1 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.1.1 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.1.0 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.1.0.rc2 lib/active_model/type/helpers/accepts_multiparameter_time.rb