aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/attribute_decorators.rb
diff options
context:
space:
mode:
authorSean Griffin & Sean Doyle <sean+seandoyle@thoughtbot.com>2014-06-27 10:23:43 -0600
committerSean Griffin <sean@thoughtbot.com>2014-06-27 11:33:32 -0600
commitccc1d3dbbec878309ea99839bb8ea2f8aca4dd72 (patch)
tree4678bf1eac2b61f9224b5300697e5b1252e060a3 /activerecord/lib/active_record/attribute_decorators.rb
parent11ac0cad081eb418dfabe8a427332347beb12a0e (diff)
downloadrails-ccc1d3dbbec878309ea99839bb8ea2f8aca4dd72.tar.gz
rails-ccc1d3dbbec878309ea99839bb8ea2f8aca4dd72.tar.bz2
rails-ccc1d3dbbec878309ea99839bb8ea2f8aca4dd72.zip
Stop using instance exec for type decorators
We are moving this behavior out to an object that we would like to keep separated from `ActiveRecord::Base`, which means not passing the class object to it. As such, we need to stop using `instance_exec`, and instead close over the subclass on global type decorators that are applied in `Base`.
Diffstat (limited to 'activerecord/lib/active_record/attribute_decorators.rb')
-rw-r--r--activerecord/lib/active_record/attribute_decorators.rb14
1 files changed, 7 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/attribute_decorators.rb b/activerecord/lib/active_record/attribute_decorators.rb
index 5745bbe0e3..5b96623b6e 100644
--- a/activerecord/lib/active_record/attribute_decorators.rb
+++ b/activerecord/lib/active_record/attribute_decorators.rb
@@ -26,7 +26,7 @@ module ActiveRecord
def add_user_provided_columns(*)
super.map do |column|
- decorated_type = attribute_type_decorations.apply(self, column.name, column.cast_type)
+ decorated_type = attribute_type_decorations.apply(column.name, column.cast_type)
column.with_type(decorated_type)
end
end
@@ -43,8 +43,8 @@ module ActiveRecord
TypeDecorator.new(@decorations.merge(*args))
end
- def apply(context, name, type)
- decorations = decorators_for(context, name, type)
+ def apply(name, type)
+ decorations = decorators_for(name, type)
decorations.inject(type) do |new_type, block|
block.call(new_type)
end
@@ -52,13 +52,13 @@ module ActiveRecord
private
- def decorators_for(context, name, type)
- matching(context, name, type).map(&:last)
+ def decorators_for(name, type)
+ matching(name, type).map(&:last)
end
- def matching(context, name, type)
+ def matching(name, type)
@decorations.values.select do |(matcher, _)|
- context.instance_exec(name, type, &matcher)
+ matcher.call(name, type)
end
end
end