From 8834b2612b7ddda70ee6a685eb0063d3daa8e63d Mon Sep 17 00:00:00 2001 From: Mikel Lindsaar Date: Sun, 17 Jan 2010 12:42:53 +1100 Subject: Adding ActiveModel::AttributeMethods documentation --- activemodel/README | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'activemodel/README') diff --git a/activemodel/README b/activemodel/README index cc687e51ed..c8814a9ea3 100644 --- a/activemodel/README +++ b/activemodel/README @@ -12,9 +12,30 @@ Active Model provides a known set of interfaces that your objects can implement to then present a common interface to the Action Pack helpers. You can include functionality from the following modules: +* Adding attribute magic to your objects + + Add prefixes and suffixes to defined attribute methods... + + class Person + include ActiveModel::AttributeMethods + + attribute_method_prefix 'clear_' + define_attribute_methods [:name, :age] + + attr_accessor :name, :age + + def clear_attribute(attr) + send("#{attr}=", nil) + end + end + + ...gives you clear_name, clear_age. + + {Learn more}[link:classes/ActiveModel/AttributeMethods.html] + * Adding callbacks to your objects - class MyClass + class Person extend ActiveModel::Callbacks define_model_callbacks :create @@ -32,7 +53,7 @@ functionality from the following modules: * For classes that already look like an Active Record object - class MyClass + class Person include ActiveModel::Conversion end -- cgit v1.2.3