public
Description: PLEASE CHECK http://github.com/lifo/docrails/wikis
Homepage: http://weblog.rubyonrails.org/2008/5/2/help-improve-rails-documentation-on-git-branch
Clone URL: git://github.com/lifo/docrails.git
Search Repo:
minor details revised in attribute_methods.rb docs
fxn (author)
Mon May 12 13:01:58 -0700 2008
commit  654e77597ba1e5b64a2be2e5e21cd542aafcfbb0
tree    3cccb96ec99c3e951e26d2417054368ecbef7fce
parent  cbd5db8f5165f013069b02414f9bf762d88f619f
...
16
17
18
19
20
 
 
 
21
 
22
 
23
24
25
26
 
 
27
28
 
29
30
31
...
60
61
62
63
64
 
 
65
66
67
...
89
90
91
92
93
 
 
 
94
95
96
97
98
...
104
105
106
107
 
108
109
110
111
112
113
 
 
114
115
116
117
118
119
 
120
121
122
123
124
...
212
213
214
215
 
216
217
218
219
 
220
221
222
 
223
224
225
...
290
291
292
293
 
294
295
296
...
321
322
323
324
325
 
 
 
326
327
328
...
16
17
18
 
 
19
20
21
22
23
24
25
26
27
 
 
28
29
30
31
32
33
34
35
...
64
65
66
 
 
67
68
69
70
71
...
93
94
95
 
 
96
97
98
99
100
101
102
103
...
109
110
111
 
112
113
114
115
116
 
 
117
118
119
120
121
122
123
 
124
125
126
127
128
129
...
217
218
219
 
220
221
222
223
 
224
225
226
 
227
228
229
230
...
295
296
297
 
298
299
300
301
...
326
327
328
 
 
329
330
331
332
333
334
0
@@ -16,16 +16,20 @@
0
 
0
     # Declare and check for suffixed attribute methods.
0
     module ClassMethods
0
- # Declare a method available for all attributes with the given suffix.
0
- # Uses method_missing and respond_to? to rewrite the method
0
+ # Declares a method available for all attributes with the given suffix.
0
+ # Uses +method_missing+ and <tt>respond_to?</tt> to rewrite the method
0
+ #
0
       # #{attr}#{suffix}(*args, &block)
0
+ #
0
       # to
0
+ #
0
       # attribute#{suffix}(#{attr}, *args, &block)
0
       #
0
- # An attribute#{suffix} instance method must exist and accept at least
0
- # the attr argument.
0
+ # An <tt>attribute#{suffix}</tt> instance method must exist and accept at least
0
+ # the +attr+ argument.
0
       #
0
       # For example:
0
+ #
0
       # class Person < ActiveRecord::Base
0
       # attribute_method_suffix '_changed?'
0
       #
0
@@ -60,8 +64,8 @@
0
         !generated_methods.empty?
0
       end
0
       
0
- # generates all the attribute related methods for columns in the database
0
- # accessors, mutators and query methods
0
+ # Generates all the attribute related methods for columns in the database
0
+ # accessors, mutators and query methods.
0
       def define_attribute_methods
0
         return if generated_methods?
0
         columns_hash.each do |name, column|
0
@@ -89,8 +93,9 @@
0
         end
0
       end
0
 
0
- # Check to see if the method is defined in the model or any of its subclasses that also derive from ActiveRecord.
0
- # Raise DangerousAttributeError if the method is defined by ActiveRecord though.
0
+ # Checks whether the method is defined in the model or any of its subclasses
0
+ # that also derive from ActiveRecord. Raises DangerousAttributeError if the
0
+ # method is defined by Active Record though.
0
       def instance_method_already_implemented?(method_name)
0
         method_name = method_name.to_s
0
         return true if method_name =~ /^id(=$|\?$|$)/
0
0
0
@@ -104,19 +109,19 @@
0
 
0
       # +cache_attributes+ allows you to declare which converted attribute values should
0
       # be cached. Usually caching only pays off for attributes with expensive conversion
0
- # methods, like time related columns (e.g. created_at, updated_at).
0
+ # methods, like time related columns (e.g. +created_at+, +updated_at+).
0
       def cache_attributes(*attribute_names)
0
         attribute_names.each {|attr| cached_attributes << attr.to_s}
0
       end
0
 
0
- # returns the attributes which are cached.
0
- # By default time related columns with datatype <tt>:datetime, :timestamp, :time, :date</tt> are cached
0
+ # Returns the attributes which are cached. By default time related columns
0
+ # with datatype <tt>:datetime, :timestamp, :time, :date</tt> are cached.
0
       def cached_attributes
0
         @cached_attributes ||=
0
           columns.select{|c| attribute_types_cached_by_default.include?(c.type)}.map(&:name).to_set
0
       end
0
 
0
- # returns true if the provided attribute is being cached
0
+ # Returns +true+ if the provided attribute is being cached.
0
       def cache_attribute?(attr_name)
0
         cached_attributes.include?(attr_name)
0
       end
0
0
0
@@ -212,14 +217,14 @@
0
     end # ClassMethods
0
 
0
 
0
- # Allows access to the object attributes, which are held in the @attributes hash, as though they
0
+ # Allows access to the object attributes, which are held in the <tt>@attributes</tt> hash, as though they
0
     # were first-class methods. So a Person class with a name attribute can use Person#name and
0
     # Person#name= and never directly use the attributes hash -- except for multiple assigns with
0
     # ActiveRecord#attributes=. A Milestone class can also ask Milestone#completed? to test that
0
- # the completed attribute is not nil or 0.
0
+ # the completed attribute is not +nil+ or 0.
0
     #
0
     # It's also possible to instantiate related objects, so a Client class belonging to the clients
0
- # table with a master_id foreign key can instantiate master through Client#master.
0
+ # table with a +master_id+ foreign key can instantiate master through Client#master.
0
     def method_missing(method_id, *args, &block)
0
       method_name = method_id.to_s
0
 
0
@@ -290,7 +295,7 @@
0
   
0
 
0
     # Updates the attribute identified by <tt>attr_name</tt> with the specified +value+. Empty strings for fixnum and float
0
- # columns are turned into nil.
0
+ # columns are turned into +nil+.
0
     def write_attribute(attr_name, value)
0
       attr_name = attr_name.to_s
0
       @attributes_cache.delete(attr_name)
0
@@ -321,8 +326,9 @@
0
       end
0
     end
0
     
0
- # A Person object with a name attribute can ask person.respond_to?("name"), person.respond_to?("name="), and
0
- # person.respond_to?("name?") which will all return true.
0
+ # A Person object with a name attribute can ask <tt>person.respond_to?("name")</tt>,
0
+ # <tt>person.respond_to?("name=")</tt>, and <tt>person.respond_to?("name?")</tt>
0
+ # which will all return +true+.
0
     alias :respond_to_without_attributes? :respond_to?
0
     def respond_to?(method, include_priv = false)
0
       method_name = method.to_s

Comments

    No one has commented yet.