aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib
diff options
context:
space:
mode:
authorFrancesco Rodriguez <lrodriguezsanc@gmail.com>2012-06-21 15:51:37 -0500
committerFrancesco Rodriguez <lrodriguezsanc@gmail.com>2012-06-21 15:51:37 -0500
commitf975c4b641b4d410b7d2ef654bba549e1dfb652e (patch)
treebc99ffd1166637d4be79140912dbf21dbe94db6b /activemodel/lib
parentb5b350ad5c1d115a54ab2ebadc44fa2d63ae50bf (diff)
downloadrails-f975c4b641b4d410b7d2ef654bba549e1dfb652e.tar.gz
rails-f975c4b641b4d410b7d2ef654bba549e1dfb652e.tar.bz2
rails-f975c4b641b4d410b7d2ef654bba549e1dfb652e.zip
add docs to AM::AttributeMethods#define_attribute_method [ci skip]
Diffstat (limited to 'activemodel/lib')
-rw-r--r--activemodel/lib/active_model/attribute_methods.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/activemodel/lib/active_model/attribute_methods.rb b/activemodel/lib/active_model/attribute_methods.rb
index 85e2f89931..96d44e3b0d 100644
--- a/activemodel/lib/active_model/attribute_methods.rb
+++ b/activemodel/lib/active_model/attribute_methods.rb
@@ -233,6 +233,31 @@ module ActiveModel
attr_names.flatten.each { |attr_name| define_attribute_method(attr_name) }
end
+ # Declares an attribute that should be prefixed and suffixed by
+ # ActiveModel::AttributeMethods.
+ #
+ # To use, pass an attribute name (as string or symbol), be sure to declare
+ # +define_attribute_method+ after you define any prefix, suffix or affix
+ # method, or they will not hook in.
+ #
+ # class Person
+ # include ActiveModel::AttributeMethods
+ #
+ # attr_accessor :name
+ # attribute_method_suffix '_short?'
+ # define_attribute_method :name
+ #
+ # private
+ #
+ # def attribute_short?(attr)
+ # send(attr).length < 5
+ # end
+ # end
+ #
+ # person = Person.new
+ # person.name = 'Bob'
+ # person.name # => "Bob"
+ # person.name_short? # => true
def define_attribute_method(attr_name)
attribute_method_matchers.each do |matcher|
method_name = matcher.method_name(attr_name)