rails 4.2.10 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -10
- metadata +37 -238
- data/guides/CHANGELOG.md +0 -93
- data/guides/Rakefile +0 -92
- data/guides/assets/images/akshaysurve.jpg +0 -0
- data/guides/assets/images/belongs_to.png +0 -0
- data/guides/assets/images/book_icon.gif +0 -0
- data/guides/assets/images/bullet.gif +0 -0
- data/guides/assets/images/chapters_icon.gif +0 -0
- data/guides/assets/images/check_bullet.gif +0 -0
- data/guides/assets/images/credits_pic_blank.gif +0 -0
- data/guides/assets/images/csrf.png +0 -0
- data/guides/assets/images/edge_badge.png +0 -0
- data/guides/assets/images/favicon.ico +0 -0
- data/guides/assets/images/feature_tile.gif +0 -0
- data/guides/assets/images/footer_tile.gif +0 -0
- data/guides/assets/images/fxn.png +0 -0
- data/guides/assets/images/getting_started/article_with_comments.png +0 -0
- data/guides/assets/images/getting_started/challenge.png +0 -0
- data/guides/assets/images/getting_started/confirm_dialog.png +0 -0
- data/guides/assets/images/getting_started/forbidden_attributes_for_new_article.png +0 -0
- data/guides/assets/images/getting_started/form_with_errors.png +0 -0
- data/guides/assets/images/getting_started/index_action_with_edit_link.png +0 -0
- data/guides/assets/images/getting_started/new_article.png +0 -0
- data/guides/assets/images/getting_started/rails_welcome.png +0 -0
- data/guides/assets/images/getting_started/routing_error_no_controller.png +0 -0
- data/guides/assets/images/getting_started/routing_error_no_route_matches.png +0 -0
- data/guides/assets/images/getting_started/show_action_for_articles.png +0 -0
- data/guides/assets/images/getting_started/template_is_missing_articles_new.png +0 -0
- data/guides/assets/images/getting_started/unknown_action_create_for_articles.png +0 -0
- data/guides/assets/images/getting_started/unknown_action_new_for_articles.png +0 -0
- data/guides/assets/images/grey_bullet.gif +0 -0
- data/guides/assets/images/habtm.png +0 -0
- data/guides/assets/images/has_many.png +0 -0
- data/guides/assets/images/has_many_through.png +0 -0
- data/guides/assets/images/has_one.png +0 -0
- data/guides/assets/images/has_one_through.png +0 -0
- data/guides/assets/images/header_backdrop.png +0 -0
- data/guides/assets/images/header_tile.gif +0 -0
- data/guides/assets/images/i18n/demo_html_safe.png +0 -0
- data/guides/assets/images/i18n/demo_localized_pirate.png +0 -0
- data/guides/assets/images/i18n/demo_translated_en.png +0 -0
- data/guides/assets/images/i18n/demo_translated_pirate.png +0 -0
- data/guides/assets/images/i18n/demo_translation_missing.png +0 -0
- data/guides/assets/images/i18n/demo_untranslated.png +0 -0
- data/guides/assets/images/icons/README +0 -5
- data/guides/assets/images/icons/callouts/1.png +0 -0
- data/guides/assets/images/icons/callouts/10.png +0 -0
- data/guides/assets/images/icons/callouts/11.png +0 -0
- data/guides/assets/images/icons/callouts/12.png +0 -0
- data/guides/assets/images/icons/callouts/13.png +0 -0
- data/guides/assets/images/icons/callouts/14.png +0 -0
- data/guides/assets/images/icons/callouts/15.png +0 -0
- data/guides/assets/images/icons/callouts/2.png +0 -0
- data/guides/assets/images/icons/callouts/3.png +0 -0
- data/guides/assets/images/icons/callouts/4.png +0 -0
- data/guides/assets/images/icons/callouts/5.png +0 -0
- data/guides/assets/images/icons/callouts/6.png +0 -0
- data/guides/assets/images/icons/callouts/7.png +0 -0
- data/guides/assets/images/icons/callouts/8.png +0 -0
- data/guides/assets/images/icons/callouts/9.png +0 -0
- data/guides/assets/images/icons/caution.png +0 -0
- data/guides/assets/images/icons/example.png +0 -0
- data/guides/assets/images/icons/home.png +0 -0
- data/guides/assets/images/icons/important.png +0 -0
- data/guides/assets/images/icons/next.png +0 -0
- data/guides/assets/images/icons/note.png +0 -0
- data/guides/assets/images/icons/prev.png +0 -0
- data/guides/assets/images/icons/tip.png +0 -0
- data/guides/assets/images/icons/up.png +0 -0
- data/guides/assets/images/icons/warning.png +0 -0
- data/guides/assets/images/nav_arrow.gif +0 -0
- data/guides/assets/images/oscardelben.jpg +0 -0
- data/guides/assets/images/polymorphic.png +0 -0
- data/guides/assets/images/radar.png +0 -0
- data/guides/assets/images/rails4_features.png +0 -0
- data/guides/assets/images/rails_guides_kindle_cover.jpg +0 -0
- data/guides/assets/images/rails_guides_logo.gif +0 -0
- data/guides/assets/images/rails_logo_remix.gif +0 -0
- data/guides/assets/images/session_fixation.png +0 -0
- data/guides/assets/images/tab_grey.gif +0 -0
- data/guides/assets/images/tab_info.gif +0 -0
- data/guides/assets/images/tab_note.gif +0 -0
- data/guides/assets/images/tab_red.gif +0 -0
- data/guides/assets/images/tab_yellow.gif +0 -0
- data/guides/assets/images/tab_yellow.png +0 -0
- data/guides/assets/images/vijaydev.jpg +0 -0
- data/guides/assets/javascripts/guides.js +0 -59
- data/guides/assets/javascripts/jquery.min.js +0 -4
- data/guides/assets/javascripts/responsive-tables.js +0 -43
- data/guides/assets/javascripts/syntaxhighlighter/shBrushAS3.js +0 -59
- data/guides/assets/javascripts/syntaxhighlighter/shBrushAppleScript.js +0 -75
- data/guides/assets/javascripts/syntaxhighlighter/shBrushBash.js +0 -59
- data/guides/assets/javascripts/syntaxhighlighter/shBrushCSharp.js +0 -65
- data/guides/assets/javascripts/syntaxhighlighter/shBrushColdFusion.js +0 -100
- data/guides/assets/javascripts/syntaxhighlighter/shBrushCpp.js +0 -97
- data/guides/assets/javascripts/syntaxhighlighter/shBrushCss.js +0 -91
- data/guides/assets/javascripts/syntaxhighlighter/shBrushDelphi.js +0 -55
- data/guides/assets/javascripts/syntaxhighlighter/shBrushDiff.js +0 -41
- data/guides/assets/javascripts/syntaxhighlighter/shBrushErlang.js +0 -52
- data/guides/assets/javascripts/syntaxhighlighter/shBrushGroovy.js +0 -67
- data/guides/assets/javascripts/syntaxhighlighter/shBrushJScript.js +0 -52
- data/guides/assets/javascripts/syntaxhighlighter/shBrushJava.js +0 -57
- data/guides/assets/javascripts/syntaxhighlighter/shBrushJavaFX.js +0 -58
- data/guides/assets/javascripts/syntaxhighlighter/shBrushPerl.js +0 -72
- data/guides/assets/javascripts/syntaxhighlighter/shBrushPhp.js +0 -88
- data/guides/assets/javascripts/syntaxhighlighter/shBrushPlain.js +0 -33
- data/guides/assets/javascripts/syntaxhighlighter/shBrushPowerShell.js +0 -74
- data/guides/assets/javascripts/syntaxhighlighter/shBrushPython.js +0 -64
- data/guides/assets/javascripts/syntaxhighlighter/shBrushRuby.js +0 -55
- data/guides/assets/javascripts/syntaxhighlighter/shBrushSass.js +0 -94
- data/guides/assets/javascripts/syntaxhighlighter/shBrushScala.js +0 -51
- data/guides/assets/javascripts/syntaxhighlighter/shBrushSql.js +0 -66
- data/guides/assets/javascripts/syntaxhighlighter/shBrushVb.js +0 -56
- data/guides/assets/javascripts/syntaxhighlighter/shBrushXml.js +0 -69
- data/guides/assets/javascripts/syntaxhighlighter/shCore.js +0 -17
- data/guides/assets/stylesheets/fixes.css +0 -16
- data/guides/assets/stylesheets/kindle.css +0 -11
- data/guides/assets/stylesheets/main.css +0 -713
- data/guides/assets/stylesheets/print.css +0 -52
- data/guides/assets/stylesheets/reset.css +0 -43
- data/guides/assets/stylesheets/responsive-tables.css +0 -50
- data/guides/assets/stylesheets/style.css +0 -13
- data/guides/assets/stylesheets/syntaxhighlighter/shCore.css +0 -226
- data/guides/assets/stylesheets/syntaxhighlighter/shCoreDefault.css +0 -328
- data/guides/assets/stylesheets/syntaxhighlighter/shCoreDjango.css +0 -331
- data/guides/assets/stylesheets/syntaxhighlighter/shCoreEclipse.css +0 -339
- data/guides/assets/stylesheets/syntaxhighlighter/shCoreEmacs.css +0 -324
- data/guides/assets/stylesheets/syntaxhighlighter/shCoreFadeToGrey.css +0 -328
- data/guides/assets/stylesheets/syntaxhighlighter/shCoreMDUltra.css +0 -324
- data/guides/assets/stylesheets/syntaxhighlighter/shCoreMidnight.css +0 -324
- data/guides/assets/stylesheets/syntaxhighlighter/shCoreRDark.css +0 -324
- data/guides/assets/stylesheets/syntaxhighlighter/shThemeDefault.css +0 -117
- data/guides/assets/stylesheets/syntaxhighlighter/shThemeDjango.css +0 -120
- data/guides/assets/stylesheets/syntaxhighlighter/shThemeEclipse.css +0 -128
- data/guides/assets/stylesheets/syntaxhighlighter/shThemeEmacs.css +0 -113
- data/guides/assets/stylesheets/syntaxhighlighter/shThemeFadeToGrey.css +0 -117
- data/guides/assets/stylesheets/syntaxhighlighter/shThemeMDUltra.css +0 -113
- data/guides/assets/stylesheets/syntaxhighlighter/shThemeMidnight.css +0 -113
- data/guides/assets/stylesheets/syntaxhighlighter/shThemeRDark.css +0 -113
- data/guides/assets/stylesheets/syntaxhighlighter/shThemeRailsGuides.css +0 -116
- data/guides/bug_report_templates/action_controller_gem.rb +0 -47
- data/guides/bug_report_templates/action_controller_master.rb +0 -54
- data/guides/bug_report_templates/active_record_gem.rb +0 -40
- data/guides/bug_report_templates/active_record_master.rb +0 -49
- data/guides/bug_report_templates/generic_gem.rb +0 -15
- data/guides/bug_report_templates/generic_master.rb +0 -26
- data/guides/rails_guides/generator.rb +0 -248
- data/guides/rails_guides/helpers.rb +0 -53
- data/guides/rails_guides/indexer.rb +0 -68
- data/guides/rails_guides/kindle.rb +0 -119
- data/guides/rails_guides/levenshtein.rb +0 -37
- data/guides/rails_guides/markdown/renderer.rb +0 -82
- data/guides/rails_guides/markdown.rb +0 -167
- data/guides/rails_guides.rb +0 -63
- data/guides/source/2_2_release_notes.md +0 -435
- data/guides/source/2_3_release_notes.md +0 -621
- data/guides/source/3_0_release_notes.md +0 -611
- data/guides/source/3_1_release_notes.md +0 -559
- data/guides/source/3_2_release_notes.md +0 -568
- data/guides/source/4_0_release_notes.md +0 -279
- data/guides/source/4_1_release_notes.md +0 -730
- data/guides/source/4_2_release_notes.md +0 -877
- data/guides/source/_license.html.erb +0 -2
- data/guides/source/_welcome.html.erb +0 -23
- data/guides/source/action_controller_overview.md +0 -1192
- data/guides/source/action_mailer_basics.md +0 -757
- data/guides/source/action_view_overview.md +0 -1561
- data/guides/source/active_job_basics.md +0 -339
- data/guides/source/active_model_basics.md +0 -554
- data/guides/source/active_record_basics.md +0 -374
- data/guides/source/active_record_callbacks.md +0 -413
- data/guides/source/active_record_migrations.md +0 -1018
- data/guides/source/active_record_postgresql.md +0 -433
- data/guides/source/active_record_querying.md +0 -1781
- data/guides/source/active_record_validations.md +0 -1179
- data/guides/source/active_support_core_extensions.md +0 -3856
- data/guides/source/active_support_instrumentation.md +0 -488
- data/guides/source/api_documentation_guidelines.md +0 -361
- data/guides/source/asset_pipeline.md +0 -1304
- data/guides/source/association_basics.md +0 -2245
- data/guides/source/autoloading_and_reloading_constants.md +0 -1311
- data/guides/source/caching_with_rails.md +0 -379
- data/guides/source/command_line.md +0 -625
- data/guides/source/configuring.md +0 -1070
- data/guides/source/contributing_to_ruby_on_rails.md +0 -628
- data/guides/source/credits.html.erb +0 -80
- data/guides/source/debugging_rails_applications.md +0 -861
- data/guides/source/development_dependencies_install.md +0 -289
- data/guides/source/documents.yaml +0 -205
- data/guides/source/engines.md +0 -1412
- data/guides/source/form_helpers.md +0 -1024
- data/guides/source/generators.md +0 -676
- data/guides/source/getting_started.md +0 -2086
- data/guides/source/i18n.md +0 -1087
- data/guides/source/index.html.erb +0 -28
- data/guides/source/initialization.md +0 -704
- data/guides/source/kindle/copyright.html.erb +0 -1
- data/guides/source/kindle/layout.html.erb +0 -27
- data/guides/source/kindle/rails_guides.opf.erb +0 -52
- data/guides/source/kindle/toc.html.erb +0 -24
- data/guides/source/kindle/toc.ncx.erb +0 -64
- data/guides/source/kindle/welcome.html.erb +0 -5
- data/guides/source/layout.html.erb +0 -140
- data/guides/source/layouts_and_rendering.md +0 -1226
- data/guides/source/maintenance_policy.md +0 -78
- data/guides/source/nested_model_forms.md +0 -228
- data/guides/source/plugins.md +0 -444
- data/guides/source/rails_application_templates.md +0 -266
- data/guides/source/rails_on_rack.md +0 -335
- data/guides/source/routing.md +0 -1155
- data/guides/source/ruby_on_rails_guides_guidelines.md +0 -127
- data/guides/source/security.md +0 -1024
- data/guides/source/testing.md +0 -1132
- data/guides/source/upgrading_ruby_on_rails.md +0 -1186
- data/guides/source/working_with_javascript_in_rails.md +0 -407
- data/guides/w3c_validator.rb +0 -97
@@ -1,361 +0,0 @@
|
|
1
|
-
API Documentation Guidelines
|
2
|
-
============================
|
3
|
-
|
4
|
-
This guide documents the Ruby on Rails API documentation guidelines.
|
5
|
-
|
6
|
-
After reading this guide, you will know:
|
7
|
-
|
8
|
-
* How to write effective prose for documentation purposes.
|
9
|
-
* Style guidelines for documenting different kinds of Ruby code.
|
10
|
-
|
11
|
-
--------------------------------------------------------------------------------
|
12
|
-
|
13
|
-
RDoc
|
14
|
-
----
|
15
|
-
|
16
|
-
The [Rails API documentation](http://api.rubyonrails.org) is generated with
|
17
|
-
[RDoc](http://docs.seattlerb.org/rdoc/).
|
18
|
-
|
19
|
-
```bash
|
20
|
-
bundle exec rake rdoc
|
21
|
-
```
|
22
|
-
|
23
|
-
Resulting HTML files can be found in the ./doc/rdoc directory.
|
24
|
-
|
25
|
-
Please consult the RDoc documentation for help with the
|
26
|
-
[markup](http://docs.seattlerb.org/rdoc/RDoc/Markup.html),
|
27
|
-
and also take into account these [additional
|
28
|
-
directives](http://docs.seattlerb.org/rdoc/RDoc/Parser/Ruby.html).
|
29
|
-
|
30
|
-
Wording
|
31
|
-
-------
|
32
|
-
|
33
|
-
Write simple, declarative sentences. Brevity is a plus: get to the point.
|
34
|
-
|
35
|
-
Write in present tense: "Returns a hash that...", rather than "Returned a hash that..." or "Will return a hash that...".
|
36
|
-
|
37
|
-
Start comments in upper case. Follow regular punctuation rules:
|
38
|
-
|
39
|
-
```ruby
|
40
|
-
# Declares an attribute reader backed by an internally-named
|
41
|
-
# instance variable.
|
42
|
-
def attr_internal_reader(*attrs)
|
43
|
-
...
|
44
|
-
end
|
45
|
-
```
|
46
|
-
|
47
|
-
Communicate to the reader the current way of doing things, both explicitly and implicitly. Use the idioms recommended in edge. Reorder sections to emphasize favored approaches if needed, etc. The documentation should be a model for best practices and canonical, modern Rails usage.
|
48
|
-
|
49
|
-
Documentation has to be concise but comprehensive. Explore and document edge cases. What happens if a module is anonymous? What if a collection is empty? What if an argument is nil?
|
50
|
-
|
51
|
-
The proper names of Rails components have a space in between the words, like "Active Support". `ActiveRecord` is a Ruby module, whereas Active Record is an ORM. All Rails documentation should consistently refer to Rails components by their proper name, and if in your next blog post or presentation you remember this tidbit and take it into account that'd be phenomenal.
|
52
|
-
|
53
|
-
Spell names correctly: Arel, Test::Unit, RSpec, HTML, MySQL, JavaScript, ERB. When in doubt, please have a look at some authoritative source like their official documentation.
|
54
|
-
|
55
|
-
Use the article "an" for "SQL", as in "an SQL statement". Also "an SQLite database".
|
56
|
-
|
57
|
-
Prefer wordings that avoid "you"s and "your"s. For example, instead of
|
58
|
-
|
59
|
-
```markdown
|
60
|
-
If you need to use `return` statements in your callbacks, it is recommended that you explicitly define them as methods.
|
61
|
-
```
|
62
|
-
|
63
|
-
use this style:
|
64
|
-
|
65
|
-
```markdown
|
66
|
-
If `return` is needed it is recommended to explicitly define a method.
|
67
|
-
```
|
68
|
-
|
69
|
-
That said, when using pronouns in reference to a hypothetical person, such as "a
|
70
|
-
user with a session cookie", gender neutral pronouns (they/their/them) should be
|
71
|
-
used. Instead of:
|
72
|
-
|
73
|
-
* he or she... use they.
|
74
|
-
* him or her... use them.
|
75
|
-
* his or her... use their.
|
76
|
-
* his or hers... use theirs.
|
77
|
-
* himself or herself... use themselves.
|
78
|
-
|
79
|
-
English
|
80
|
-
-------
|
81
|
-
|
82
|
-
Please use American English (*color*, *center*, *modularize*, etc). See [a list of American and British English spelling differences here](http://en.wikipedia.org/wiki/American_and_British_English_spelling_differences).
|
83
|
-
|
84
|
-
Example Code
|
85
|
-
------------
|
86
|
-
|
87
|
-
Choose meaningful examples that depict and cover the basics as well as interesting points or gotchas.
|
88
|
-
|
89
|
-
Use two spaces to indent chunks of code--that is, for markup purposes, two spaces with respect to the left margin. The examples themselves should use [Rails coding conventions](contributing_to_ruby_on_rails.html#follow-the-coding-conventions).
|
90
|
-
|
91
|
-
Short docs do not need an explicit "Examples" label to introduce snippets; they just follow paragraphs:
|
92
|
-
|
93
|
-
```ruby
|
94
|
-
# Converts a collection of elements into a formatted string by
|
95
|
-
# calling +to_s+ on all elements and joining them.
|
96
|
-
#
|
97
|
-
# Blog.all.to_formatted_s # => "First PostSecond PostThird Post"
|
98
|
-
```
|
99
|
-
|
100
|
-
On the other hand, big chunks of structured documentation may have a separate "Examples" section:
|
101
|
-
|
102
|
-
```ruby
|
103
|
-
# ==== Examples
|
104
|
-
#
|
105
|
-
# Person.exists?(5)
|
106
|
-
# Person.exists?('5')
|
107
|
-
# Person.exists?(name: "David")
|
108
|
-
# Person.exists?(['name LIKE ?', "%#{query}%"])
|
109
|
-
```
|
110
|
-
|
111
|
-
The results of expressions follow them and are introduced by "# => ", vertically aligned:
|
112
|
-
|
113
|
-
```ruby
|
114
|
-
# For checking if an integer is even or odd.
|
115
|
-
#
|
116
|
-
# 1.even? # => false
|
117
|
-
# 1.odd? # => true
|
118
|
-
# 2.even? # => true
|
119
|
-
# 2.odd? # => false
|
120
|
-
```
|
121
|
-
|
122
|
-
If a line is too long, the comment may be placed on the next line:
|
123
|
-
|
124
|
-
```ruby
|
125
|
-
# label(:article, :title)
|
126
|
-
# # => <label for="article_title">Title</label>
|
127
|
-
#
|
128
|
-
# label(:article, :title, "A short title")
|
129
|
-
# # => <label for="article_title">A short title</label>
|
130
|
-
#
|
131
|
-
# label(:article, :title, "A short title", class: "title_label")
|
132
|
-
# # => <label for="article_title" class="title_label">A short title</label>
|
133
|
-
```
|
134
|
-
|
135
|
-
Avoid using any printing methods like `puts` or `p` for that purpose.
|
136
|
-
|
137
|
-
On the other hand, regular comments do not use an arrow:
|
138
|
-
|
139
|
-
```ruby
|
140
|
-
# polymorphic_url(record) # same as comment_url(record)
|
141
|
-
```
|
142
|
-
|
143
|
-
Booleans
|
144
|
-
--------
|
145
|
-
|
146
|
-
In predicates and flags prefer documenting boolean semantics over exact values.
|
147
|
-
|
148
|
-
When "true" or "false" are used as defined in Ruby use regular font. The
|
149
|
-
singletons `true` and `false` need fixed-width font. Please avoid terms like
|
150
|
-
"truthy", Ruby defines what is true and false in the language, and thus those
|
151
|
-
words have a technical meaning and need no substitutes.
|
152
|
-
|
153
|
-
As a rule of thumb, do not document singletons unless absolutely necessary. That
|
154
|
-
prevents artificial constructs like `!!` or ternaries, allows refactors, and the
|
155
|
-
code does not need to rely on the exact values returned by methods being called
|
156
|
-
in the implementation.
|
157
|
-
|
158
|
-
For example:
|
159
|
-
|
160
|
-
```markdown
|
161
|
-
`config.action_mailer.perform_deliveries` specifies whether mail will actually be delivered and is true by default
|
162
|
-
```
|
163
|
-
|
164
|
-
the user does not need to know which is the actual default value of the flag,
|
165
|
-
and so we only document its boolean semantics.
|
166
|
-
|
167
|
-
An example with a predicate:
|
168
|
-
|
169
|
-
```ruby
|
170
|
-
# Returns true if the collection is empty.
|
171
|
-
#
|
172
|
-
# If the collection has been loaded
|
173
|
-
# it is equivalent to <tt>collection.size.zero?</tt>. If the
|
174
|
-
# collection has not been loaded, it is equivalent to
|
175
|
-
# <tt>collection.exists?</tt>. If the collection has not already been
|
176
|
-
# loaded and you are going to fetch the records anyway it is better to
|
177
|
-
# check <tt>collection.length.zero?</tt>.
|
178
|
-
def empty?
|
179
|
-
if loaded?
|
180
|
-
size.zero?
|
181
|
-
else
|
182
|
-
@target.blank? && !scope.exists?
|
183
|
-
end
|
184
|
-
end
|
185
|
-
```
|
186
|
-
|
187
|
-
The API is careful not to commit to any particular value, the method has
|
188
|
-
predicate semantics, that's enough.
|
189
|
-
|
190
|
-
File Names
|
191
|
-
----------
|
192
|
-
|
193
|
-
As a rule of thumb, use filenames relative to the application root:
|
194
|
-
|
195
|
-
```
|
196
|
-
config/routes.rb # YES
|
197
|
-
routes.rb # NO
|
198
|
-
RAILS_ROOT/config/routes.rb # NO
|
199
|
-
```
|
200
|
-
|
201
|
-
Fonts
|
202
|
-
-----
|
203
|
-
|
204
|
-
### Fixed-width Font
|
205
|
-
|
206
|
-
Use fixed-width fonts for:
|
207
|
-
|
208
|
-
* Constants, in particular class and module names.
|
209
|
-
* Method names.
|
210
|
-
* Literals like `nil`, `false`, `true`, `self`.
|
211
|
-
* Symbols.
|
212
|
-
* Method parameters.
|
213
|
-
* File names.
|
214
|
-
|
215
|
-
```ruby
|
216
|
-
class Array
|
217
|
-
# Calls +to_param+ on all its elements and joins the result with
|
218
|
-
# slashes. This is used by +url_for+ in Action Pack.
|
219
|
-
def to_param
|
220
|
-
collect { |e| e.to_param }.join '/'
|
221
|
-
end
|
222
|
-
end
|
223
|
-
```
|
224
|
-
|
225
|
-
WARNING: Using `+...+` for fixed-width font only works with simple content like
|
226
|
-
ordinary method names, symbols, paths (with forward slashes), etc. Please use
|
227
|
-
`<tt>...</tt>` for everything else, notably class or module names with a
|
228
|
-
namespace as in `<tt>ActiveRecord::Base</tt>`.
|
229
|
-
|
230
|
-
You can quickly test the RDoc output with the following command:
|
231
|
-
|
232
|
-
```
|
233
|
-
$ echo "+:to_param+" | rdoc --pipe
|
234
|
-
#=> <p><code>:to_param</code></p>
|
235
|
-
```
|
236
|
-
|
237
|
-
### Regular Font
|
238
|
-
|
239
|
-
When "true" and "false" are English words rather than Ruby keywords use a regular font:
|
240
|
-
|
241
|
-
```ruby
|
242
|
-
# Runs all the validations within the specified context.
|
243
|
-
# Returns true if no errors are found, false otherwise.
|
244
|
-
#
|
245
|
-
# If the argument is false (default is +nil+), the context is
|
246
|
-
# set to <tt>:create</tt> if <tt>new_record?</tt> is true,
|
247
|
-
# and to <tt>:update</tt> if it is not.
|
248
|
-
#
|
249
|
-
# Validations with no <tt>:on</tt> option will run no
|
250
|
-
# matter the context. Validations with # some <tt>:on</tt>
|
251
|
-
# option will only run in the specified context.
|
252
|
-
def valid?(context = nil)
|
253
|
-
...
|
254
|
-
end
|
255
|
-
```
|
256
|
-
|
257
|
-
Description Lists
|
258
|
-
-----------------
|
259
|
-
|
260
|
-
In lists of options, parameters, etc. use a hyphen between the item and its description (reads better than a colon because normally options are symbols):
|
261
|
-
|
262
|
-
```ruby
|
263
|
-
# * <tt>:allow_nil</tt> - Skip validation if attribute is +nil+.
|
264
|
-
```
|
265
|
-
|
266
|
-
The description starts in upper case and ends with a full stop-it's standard English.
|
267
|
-
|
268
|
-
Dynamically Generated Methods
|
269
|
-
-----------------------------
|
270
|
-
|
271
|
-
Methods created with `(module|class)_eval(STRING)` have a comment by their side with an instance of the generated code. That comment is 2 spaces away from the template:
|
272
|
-
|
273
|
-
```ruby
|
274
|
-
for severity in Severity.constants
|
275
|
-
class_eval <<-EOT, __FILE__, __LINE__
|
276
|
-
def #{severity.downcase}(message = nil, progname = nil, &block) # def debug(message = nil, progname = nil, &block)
|
277
|
-
add(#{severity}, message, progname, &block) # add(DEBUG, message, progname, &block)
|
278
|
-
end # end
|
279
|
-
#
|
280
|
-
def #{severity.downcase}? # def debug?
|
281
|
-
#{severity} >= @level # DEBUG >= @level
|
282
|
-
end # end
|
283
|
-
EOT
|
284
|
-
end
|
285
|
-
```
|
286
|
-
|
287
|
-
If the resulting lines are too wide, say 200 columns or more, put the comment above the call:
|
288
|
-
|
289
|
-
```ruby
|
290
|
-
# def self.find_by_login_and_activated(*args)
|
291
|
-
# options = args.extract_options!
|
292
|
-
# ...
|
293
|
-
# end
|
294
|
-
self.class_eval %{
|
295
|
-
def self.#{method_id}(*args)
|
296
|
-
options = args.extract_options!
|
297
|
-
...
|
298
|
-
end
|
299
|
-
}
|
300
|
-
```
|
301
|
-
|
302
|
-
Method Visibility
|
303
|
-
-----------------
|
304
|
-
|
305
|
-
When writing documentation for Rails, it's important to understand the difference between public user-facing API vs internal API.
|
306
|
-
|
307
|
-
Rails, like most libraries, uses the private keyword from Ruby for defining internal API. However, public API follows a slightly different convention. Instead of assuming all public methods are designed for user consumption, Rails uses the `:nodoc:` directive to annotate these kinds of methods as internal API.
|
308
|
-
|
309
|
-
This means that there are methods in Rails with `public` visibility that aren't meant for user consumption.
|
310
|
-
|
311
|
-
An example of this is `ActiveRecord::Core::ClassMethods#arel_table`:
|
312
|
-
|
313
|
-
```ruby
|
314
|
-
module ActiveRecord::Core::ClassMethods
|
315
|
-
def arel_table #:nodoc:
|
316
|
-
# do some magic..
|
317
|
-
end
|
318
|
-
end
|
319
|
-
```
|
320
|
-
|
321
|
-
If you thought, "this method looks like a public class method for `ActiveRecord::Core`", you were right. But actually the Rails team doesn't want users to rely on this method. So they mark it as `:nodoc:` and it's removed from public documentation. The reasoning behind this is to allow the team to change these methods according to their internal needs across releases as they see fit. The name of this method could change, or the return value, or this entire class may disappear; there's no guarantee and so you shouldn't depend on this API in your plugins or applications. Otherwise, you risk your app or gem breaking when you upgrade to a newer release of Rails.
|
322
|
-
|
323
|
-
As a contributor, it's important to think about whether this API is meant for end-user consumption. The Rails team is committed to not making any breaking changes to public API across releases without going through a full deprecation cycle. It's recommended that you `:nodoc:` any of your internal methods/classes unless they're already private (meaning visibility), in which case it's internal by default. Once the API stabilizes the visibility can change, but changing public API is much harder due to backwards compatibility.
|
324
|
-
|
325
|
-
A class or module is marked with `:nodoc:` to indicate that all methods are internal API and should never be used directly.
|
326
|
-
|
327
|
-
If you come across an existing `:nodoc:` you should tread lightly. Consider asking someone from the core team or author of the code before removing it. This should almost always happen through a pull request instead of the docrails project.
|
328
|
-
|
329
|
-
A `:nodoc:` should never be added simply because a method or class is missing documentation. There may be an instance where an internal public method wasn't given a `:nodoc:` by mistake, for example when switching a method from private to public visibility. When this happens it should be discussed over a PR on a case-by-case basis and never committed directly to docrails.
|
330
|
-
|
331
|
-
To summarize, the Rails team uses `:nodoc:` to mark publicly visible methods and classes for internal use; changes to the visibility of API should be considered carefully and discussed over a pull request first.
|
332
|
-
|
333
|
-
Regarding the Rails Stack
|
334
|
-
-------------------------
|
335
|
-
|
336
|
-
When documenting parts of Rails API, it's important to remember all of the
|
337
|
-
pieces that go into the Rails stack.
|
338
|
-
|
339
|
-
This means that behavior may change depending on the scope or context of the
|
340
|
-
method or class you're trying to document.
|
341
|
-
|
342
|
-
In various places there is different behavior when you take the entire stack
|
343
|
-
into account, one such example is
|
344
|
-
`ActionView::Helpers::AssetTagHelper#image_tag`:
|
345
|
-
|
346
|
-
```ruby
|
347
|
-
# image_tag("icon.png")
|
348
|
-
# # => <img alt="Icon" src="/assets/icon.png" />
|
349
|
-
```
|
350
|
-
|
351
|
-
Although the default behavior for `#image_tag` is to always return
|
352
|
-
`/images/icon.png`, we take into account the full Rails stack (including the
|
353
|
-
Asset Pipeline) we may see the result seen above.
|
354
|
-
|
355
|
-
We're only concerned with the behavior experienced when using the full default
|
356
|
-
Rails stack.
|
357
|
-
|
358
|
-
In this case, we want to document the behavior of the _framework_, and not just
|
359
|
-
this specific method.
|
360
|
-
|
361
|
-
If you have a question on how the Rails team handles certain API, don't hesitate to open a ticket or send a patch to the [issue tracker](https://github.com/rails/rails/issues).
|