diff options
author | Sean Griffin <sean@thoughtbot.com> | 2015-02-07 13:52:23 -0700 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2015-02-07 13:52:23 -0700 |
commit | 631707a572fe14f3bbea2779cc97fcc581048d62 (patch) | |
tree | 25646486f0275d24099afb557fc7f4d2180f0caf /activerecord/lib/active_record/type/date_time.rb | |
parent | bdeeca84e34d3e0863a6fd03defb9c95fd0241d9 (diff) | |
download | rails-631707a572fe14f3bbea2779cc97fcc581048d62.tar.gz rails-631707a572fe14f3bbea2779cc97fcc581048d62.tar.bz2 rails-631707a572fe14f3bbea2779cc97fcc581048d62.zip |
Push multi-parameter assignement into the types
This allows us to remove `Type::Value#klass`, as it was only used for
multi-parameter assignment to reach into the types internals. The
relevant type objects now accept a hash in addition to their previous
accepted arguments to `type_cast_from_user`. This required minor
modifications to the tests, since previously they were relying on the
fact that mulit-parameter assignement was reaching into the internals of
time zone aware attributes. In reaility, changing those properties at
runtime wouldn't change the accessor methods for all other forms of
assignment.
Diffstat (limited to 'activerecord/lib/active_record/type/date_time.rb')
-rw-r--r-- | activerecord/lib/active_record/type/date_time.rb | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/type/date_time.rb b/activerecord/lib/active_record/type/date_time.rb index 0a737815bc..922f0d8fef 100644 --- a/activerecord/lib/active_record/type/date_time.rb +++ b/activerecord/lib/active_record/type/date_time.rb @@ -2,6 +2,9 @@ module ActiveRecord module Type class DateTime < Value # :nodoc: include TimeValue + include Helpers::AcceptsMultiparameterTime.new( + defaults: { 4 => 0, 5 => 0 } + ) def type :datetime @@ -42,6 +45,14 @@ module ActiveRecord new_time(*time_hash.values_at(:year, :mon, :mday, :hour, :min, :sec, :sec_fraction, :offset)) end + + def value_from_multiparameter_assignment(values_hash) + missing_parameter = (1..3).detect { |key| !values_hash.key?(key) } + if missing_parameter + raise ArgumentError, missing_parameter + end + super + end end end end |