From 22cc2b86f790b08bf58311bb6eb3bb148cb1dea9 Mon Sep 17 00:00:00 2001 From: Sean Griffin Date: Mon, 21 Sep 2015 09:24:39 -0600 Subject: Various stylistic nitpicks We do not need to require each file from AM individually, the type module does that for us. Even if the classes are extremely small right now, I'd rather keep any custom classes needed by AR in their own files, as they can easily have more complex changes in the future. --- activerecord/lib/active_record/type.rb | 56 +++++++--------------- activerecord/lib/active_record/type/date.rb | 7 +++ activerecord/lib/active_record/type/date_time.rb | 7 +++ .../lib/active_record/type/internal/timezone.rb | 2 +- activerecord/lib/active_record/type/time.rb | 8 ++++ activerecord/lib/active_record/type/type_map.rb | 2 +- 6 files changed, 40 insertions(+), 42 deletions(-) create mode 100644 activerecord/lib/active_record/type/date.rb create mode 100644 activerecord/lib/active_record/type/date_time.rb create mode 100644 activerecord/lib/active_record/type/time.rb (limited to 'activerecord') diff --git a/activerecord/lib/active_record/type.rb b/activerecord/lib/active_record/type.rb index 5b089d66a0..28ab07e868 100644 --- a/activerecord/lib/active_record/type.rb +++ b/activerecord/lib/active_record/type.rb @@ -1,24 +1,12 @@ -require 'active_model/type/helpers' -require 'active_model/type/value' - -require 'active_model/type/big_integer' -require 'active_model/type/binary' -require 'active_model/type/boolean' -require 'active_model/type/date' -require 'active_model/type/date_time' -require 'active_model/type/decimal' -require 'active_model/type/decimal_without_scale' -require 'active_model/type/float' -require 'active_model/type/integer' -require 'active_model/type/string' -require 'active_model/type/text' -require 'active_model/type/time' -require 'active_model/type/unsigned_integer' - -require 'active_model/type/registry' +require 'active_model/type' require 'active_record/type/internal/abstract_json' require 'active_record/type/internal/timezone' + +require 'active_record/type/date' +require 'active_record/type/date_time' +require 'active_record/type/time' + require 'active_record/type/serialized' require 'active_record/type/adapter_specific_registry' @@ -56,29 +44,17 @@ module ActiveRecord end end - class Date < ActiveModel::Type::Date - include Internal::Timezone - end - - class DateTime < ActiveModel::Type::DateTime - include Internal::Timezone - end - class Time < ActiveModel::Type::Time - include Internal::Timezone - end - - Helpers = ActiveModel::Type::Helpers - BigInteger = ActiveModel::Type::BigInteger - Binary = ActiveModel::Type::Binary - Boolean = ActiveModel::Type::Boolean - Decimal = ActiveModel::Type::Decimal + BigInteger = ActiveModel::Type::BigInteger + Binary = ActiveModel::Type::Binary + Boolean = ActiveModel::Type::Boolean + Decimal = ActiveModel::Type::Decimal DecimalWithoutScale = ActiveModel::Type::DecimalWithoutScale - Float = ActiveModel::Type::Float - Integer = ActiveModel::Type::Integer - String = ActiveModel::Type::String - Text = ActiveModel::Type::Text - UnsignedInteger = ActiveModel::Type::UnsignedInteger - Value = ActiveModel::Type::Value + Float = ActiveModel::Type::Float + Integer = ActiveModel::Type::Integer + String = ActiveModel::Type::String + Text = ActiveModel::Type::Text + UnsignedInteger = ActiveModel::Type::UnsignedInteger + Value = ActiveModel::Type::Value register(:big_integer, Type::BigInteger, override: false) register(:binary, Type::Binary, override: false) diff --git a/activerecord/lib/active_record/type/date.rb b/activerecord/lib/active_record/type/date.rb new file mode 100644 index 0000000000..ccafed054e --- /dev/null +++ b/activerecord/lib/active_record/type/date.rb @@ -0,0 +1,7 @@ +module ActiveRecord + module Type + class Date < ActiveModel::Type::Date + include Internal::Timezone + end + end +end diff --git a/activerecord/lib/active_record/type/date_time.rb b/activerecord/lib/active_record/type/date_time.rb new file mode 100644 index 0000000000..1fb9380ecd --- /dev/null +++ b/activerecord/lib/active_record/type/date_time.rb @@ -0,0 +1,7 @@ +module ActiveRecord + module Type + class DateTime < ActiveModel::Type::DateTime + include Internal::Timezone + end + end +end diff --git a/activerecord/lib/active_record/type/internal/timezone.rb b/activerecord/lib/active_record/type/internal/timezone.rb index 07dbb0b2c6..947e06158a 100644 --- a/activerecord/lib/active_record/type/internal/timezone.rb +++ b/activerecord/lib/active_record/type/internal/timezone.rb @@ -5,7 +5,7 @@ module ActiveRecord def is_utc? ActiveRecord::Base.default_timezone == :utc end - + def default_timezone ActiveRecord::Base.default_timezone end diff --git a/activerecord/lib/active_record/type/time.rb b/activerecord/lib/active_record/type/time.rb new file mode 100644 index 0000000000..70988d84ff --- /dev/null +++ b/activerecord/lib/active_record/type/time.rb @@ -0,0 +1,8 @@ +module ActiveRecord + module Type + class Time < ActiveModel::Type::Time + include Internal::Timezone + end + end +end + diff --git a/activerecord/lib/active_record/type/type_map.rb b/activerecord/lib/active_record/type/type_map.rb index 8ce36cc9af..81d7ed39bb 100644 --- a/activerecord/lib/active_record/type/type_map.rb +++ b/activerecord/lib/active_record/type/type_map.rb @@ -57,7 +57,7 @@ module ActiveRecord end def default_value - @default_value ||= Value.new + @default_value ||= ActiveModel::Type::Value.new end end end -- cgit v1.2.3