aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/types.rb
diff options
context:
space:
mode:
authorEric Chapweske <eric@chapweske.com>2009-10-17 12:37:15 -0500
committerJoshua Peek <josh@joshpeek.com>2009-10-17 12:37:15 -0500
commitf936a1f100e75082081e782e5cceb272885c2df7 (patch)
tree6c5091faa38f15765b3be153141b81d693b02d18 /activerecord/lib/active_record/types.rb
parente13d232150921cdf0ec3d713caefa628d235152e (diff)
downloadrails-f936a1f100e75082081e782e5cceb272885c2df7.tar.gz
rails-f936a1f100e75082081e782e5cceb272885c2df7.tar.bz2
rails-f936a1f100e75082081e782e5cceb272885c2df7.zip
Refactoring attributes/types [#3348 state:resolved]
Signed-off-by: Joshua Peek <josh@joshpeek.com>
Diffstat (limited to 'activerecord/lib/active_record/types.rb')
-rw-r--r--activerecord/lib/active_record/types.rb38
1 files changed, 38 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/types.rb b/activerecord/lib/active_record/types.rb
new file mode 100644
index 0000000000..74f569352b
--- /dev/null
+++ b/activerecord/lib/active_record/types.rb
@@ -0,0 +1,38 @@
+module ActiveRecord
+ module Types
+ extend ActiveSupport::Concern
+
+ module ClassMethods
+
+ def attribute_types
+ attribute_types = {}
+ columns.each do |column|
+ options = {}
+ options[:time_zone_aware] = time_zone_aware?(column.name)
+ options[:serialize] = serialized_attributes[column.name]
+
+ attribute_types[column.name] = to_type(column, options)
+ end
+ attribute_types
+ end
+
+ private
+
+ def to_type(column, options = {})
+ type_class = if options[:time_zone_aware]
+ Type::TimeWithZone
+ elsif options[:serialize]
+ Type::Serialize
+ elsif [ :integer, :float, :decimal ].include?(column.type)
+ Type::Number
+ else
+ Type::Object
+ end
+
+ type_class.new(column, options)
+ end
+
+ end
+
+ end
+end