aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/attribute_methods.rb
diff options
context:
space:
mode:
authorBen Toews <mastahyeti@users.noreply.github.com>2017-02-08 11:23:26 -0700
committerMatthew Draper <matthew@trebex.net>2017-11-09 22:32:16 +1030
commitf989b341eccc6a86fd1ddfff7f1441920855c84e (patch)
tree9cde6c82ff135be475431e308c1f59b1d57a0cae /activerecord/lib/active_record/attribute_methods.rb
parentbe6e1b8f7dbce1940f47339657faab2c1fdeaa54 (diff)
downloadrails-f989b341eccc6a86fd1ddfff7f1441920855c84e.tar.gz
rails-f989b341eccc6a86fd1ddfff7f1441920855c84e.tar.bz2
rails-f989b341eccc6a86fd1ddfff7f1441920855c84e.zip
add config to check arguments to unsafe AR methods
Diffstat (limited to 'activerecord/lib/active_record/attribute_methods.rb')
-rw-r--r--activerecord/lib/active_record/attribute_methods.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/attribute_methods.rb b/activerecord/lib/active_record/attribute_methods.rb
index 23d2aef214..fa0d79ba5f 100644
--- a/activerecord/lib/active_record/attribute_methods.rb
+++ b/activerecord/lib/active_record/attribute_methods.rb
@@ -167,6 +167,22 @@ module ActiveRecord
end
end
+ # Can the given name be treated as a column name? Returns true if name
+ # is attribute or attribute alias.
+ #
+ # class Person < ActiveRecord::Base
+ # end
+ #
+ # Person.respond_to_attribute?(:name)
+ # # => true
+ #
+ # Person.respond_to_attribute?("foo")
+ # # => false
+ def respond_to_attribute?(name)
+ name = name.to_s
+ attribute_names.include?(name) || attribute_aliases.include?(name)
+ end
+
# Returns true if the given attribute exists, otherwise false.
#
# class Person < ActiveRecord::Base