diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-06-16 14:55:01 -0600 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-06-16 15:09:39 -0600 |
commit | 74af9f7fd781501e7f4a4746afd91b1bd5f77ddc (patch) | |
tree | 47c95a656a5b0aa0a8a6c72c1282832e13122004 /activerecord/lib/active_record/model_schema.rb | |
parent | 88714deb677f598fa40f6e7b61a083a5461d07fd (diff) | |
download | rails-74af9f7fd781501e7f4a4746afd91b1bd5f77ddc.tar.gz rails-74af9f7fd781501e7f4a4746afd91b1bd5f77ddc.tar.bz2 rails-74af9f7fd781501e7f4a4746afd91b1bd5f77ddc.zip |
Promote time zone aware attributes to a first class type decorator
This refactoring revealed the need for another form of decoration, which
takes a proc to select which it applies to (There's a *lot* of cases
where this form can be used). To avoid duplication, we can re-implement
the old decoration in terms of the proc-based decoration.
The reason we're `instance_exec`ing the matcher is for cases such as
time zone aware attributes, where a decorator is defined in a parent
class, and a method called in the matcher is overridden by a child
class. The matcher will close over the parent, and evaluate in its
context, which is not the behavior we want.
Diffstat (limited to 'activerecord/lib/active_record/model_schema.rb')
-rw-r--r-- | activerecord/lib/active_record/model_schema.rb | 20 |
1 files changed, 1 insertions, 19 deletions
diff --git a/activerecord/lib/active_record/model_schema.rb b/activerecord/lib/active_record/model_schema.rb index 9e1afd32e6..b9558b0752 100644 --- a/activerecord/lib/active_record/model_schema.rb +++ b/activerecord/lib/active_record/model_schema.rb @@ -220,27 +220,13 @@ module ActiveRecord end def column_types # :nodoc: - @column_types ||= decorate_types(build_types_hash) + @column_types ||= Hash[columns.map { |column| [column.name, column.cast_type] }] end def type_for_attribute(attr_name) # :nodoc: column_types.fetch(attr_name) { Type::Value.new } end - def decorate_types(types) # :nodoc: - return if types.empty? - - @time_zone_column_names ||= self.columns_hash.find_all do |name, col| - create_time_zone_conversion_attribute?(name, col) - end.map!(&:first) - - @time_zone_column_names.each do |name| - types[name] = AttributeMethods::TimeZoneConversion::Type.new(types[name]) - end - - types - end - # Returns a hash where the keys are column names and the values are # default values when instantiating the AR object for this table. def column_defaults @@ -335,10 +321,6 @@ module ActiveRecord base.table_name end end - - def build_types_hash - Hash[columns.map { |column| [column.name, column.cast_type] }] - end end end end |