aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/model_schema.rb
diff options
context:
space:
mode:
authorSean Griffin <sean@seantheprogrammer.com>2016-01-19 13:18:08 -0700
committerSean Griffin <sean@seantheprogrammer.com>2016-01-19 13:19:54 -0700
commit12cd2c494d9c6cbec0594b8e63228fda9741e10d (patch)
tree1fb93d34f26c49d0ad8289c911c201677e16c93d /activerecord/lib/active_record/model_schema.rb
parenta4c82d8e6473ac125929dc2a652eeea348a37246 (diff)
downloadrails-12cd2c494d9c6cbec0594b8e63228fda9741e10d.tar.gz
rails-12cd2c494d9c6cbec0594b8e63228fda9741e10d.tar.bz2
rails-12cd2c494d9c6cbec0594b8e63228fda9741e10d.zip
Add `ModelSchema::type_for_attribute` to the public API
We want this method to be the single canonical source of information about type metadata related to a model. This is the method I've been continuously recommending people use if they need this sort of access, as I have no plans to remove or change it at any point in the future. We can do ourselves a favor and get people to use this instead of relying on some other part of the internals that they shouldn't be by making this method public.
Diffstat (limited to 'activerecord/lib/active_record/model_schema.rb')
-rw-r--r--activerecord/lib/active_record/model_schema.rb13
1 files changed, 12 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/model_schema.rb b/activerecord/lib/active_record/model_schema.rb
index f26c8471bc..722d7b5fce 100644
--- a/activerecord/lib/active_record/model_schema.rb
+++ b/activerecord/lib/active_record/model_schema.rb
@@ -255,7 +255,18 @@ module ActiveRecord
@attribute_types ||= Hash.new(Type::Value.new)
end
- def type_for_attribute(attr_name) # :nodoc:
+ # Returns the type of the attribute with the given name, after applying
+ # all modifiers. This method is the only valid source of information for
+ # anything related to the types of a model's attributes. This method will
+ # access the database and load the model's schema if it is required.
+ #
+ # The return value of this method will implement the interface described
+ # by ActiveModel::Type::Value (though the object itself may not subclass
+ # it).
+ #
+ # +attr_name+ The name of the attribute to retrieve the type for. Must be
+ # a string
+ def type_for_attribute(attr_name)
attribute_types[attr_name]
end