Sha256: d7ac6ab5ebb60ca9291034682568e1a29ee5f551855ee6d735bccc78671f5c8e

Contents?: true

Size: 1.01 KB

Versions: 38

Compression:

Stored size: 1.01 KB

Contents

module ActiveModel
  module Type
    module Helpers
      class AcceptsMultiparameterTime < Module # :nodoc:
        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

38 entries across 37 versions & 5 rubygems

Version Path
activemodel-5.0.7.2 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.0.7.1 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.0.7 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.0.6 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.0.6.rc1 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.0.5 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.0.5.rc2 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.0.5.rc1 lib/active_model/type/helpers/accepts_multiparameter_time.rb
tdiary-5.0.5 vendor/bundle/gems/activemodel-5.0.2/lib/active_model/type/helpers/accepts_multiparameter_time.rb
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/activemodel-5.0.2/lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.0.4 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.0.4.rc1 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.0.3 lib/active_model/type/helpers/accepts_multiparameter_time.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/activemodel-5.0.2/lib/active_model/type/helpers/accepts_multiparameter_time.rb
tdiary-5.0.4 vendor/bundle/gems/activemodel-5.0.2/lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.0.2 lib/active_model/type/helpers/accepts_multiparameter_time.rb
activemodel-5.0.2.rc1 lib/active_model/type/helpers/accepts_multiparameter_time.rb
autocompl-0.2.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/activemodel-5.0.1/lib/active_model/type/helpers/accepts_multiparameter_time.rb
autocompl-0.2.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/activemodel-5.0.1/lib/active_model/type/helpers/accepts_multiparameter_time.rb
autocompl-0.2.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/activemodel-5.0.1/lib/active_model/type/helpers/accepts_multiparameter_time.rb