1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

applied guidelines to "# =>"

This commit is contained in:
Paco Guzman 2010-08-12 17:09:58 +02:00
parent 599c505837
commit 8a2b69b727
11 changed files with 51 additions and 51 deletions

View file

@ -65,8 +65,8 @@ simply call the method and optionally call +deliver+ on the return value.
Calling the method returns a Mail Message object:
message = Notifier.welcome #=> Returns a Mail::Message object
message.deliver #=> delivers the email
message = Notifier.welcome # => Returns a Mail::Message object
message.deliver # => delivers the email
Or you can just chain the methods together like:

View file

@ -107,8 +107,8 @@ modules:
extend ActiveModel::Naming
end
NamedPerson.model_name #=> "NamedPerson"
NamedPerson.model_name.human #=> "Named person"
NamedPerson.model_name # => "NamedPerson"
NamedPerson.model_name.human # => "Named person"
{Learn more}[link:classes/ActiveModel/Naming.html]
@ -139,7 +139,7 @@ modules:
end
Person.human_attribute_name('my_attribute')
#=> "My attribute"
# => "My attribute"
{Learn more}[link:classes/ActiveModel/Translation.html]
@ -157,7 +157,7 @@ modules:
person = Person.new
person.first_name = 'zoolander'
person.valid? #=> false
person.valid? # => false
{Learn more}[link:classes/ActiveModel/Validations.html]
@ -176,9 +176,9 @@ modules:
end
p = ValidatorPerson.new
p.valid? #=> false
p.errors.full_messages #=> ["Name must exist"]
p.valid? # => false
p.errors.full_messages # => ["Name must exist"]
p.name = "Bob"
p.valid? #=> true
p.valid? # => true
{Learn more}[link:classes/ActiveModel/Validator.html]

View file

@ -966,7 +966,7 @@ during calendar reform. #7649, #7724 [fedot, Geoff Buesing]
* Made increment_counter/decrement_counter play nicely with optimistic locking, and added a more general update_counters method [Jamis Buck]
* Reworked David's query cache to be available as Model.cache {...}. For the duration of the block no select query should be run more then once. Any inserts/deletes/executes will flush the whole cache however [Tobias Lütke]
Task.cache { Task.find(1); Task.find(1) } #=> 1 query
Task.cache { Task.find(1); Task.find(1) } # => 1 query
* When dealing with SQLite3, use the table_info pragma helper, so that the bindings can do some translation for when sqlite3 breaks incompatibly between point releases. [Jamis Buck]

View file

@ -72,20 +72,20 @@ module ActiveRecord
#
# post = Post.new(:title => 'ruby rocks')
# post.comments.build(:body => 'hello world')
# post.save #=> will save both post and comment
# post.save # => will save both post and comment
#
# post = Post.create(:title => 'ruby rocks')
# post.comments.build(:body => 'hello world')
# post.save #=> will save both post and comment
# post.save # => will save both post and comment
#
# post = Post.create(:title => 'ruby rocks')
# post.comments.create(:body => 'hello world')
# post.save #=> will save both post and comment
# post.save # => will save both post and comment
#
# post = Post.create(:title => 'ruby rocks')
# post.comments.build(:body => 'hello world')
# post.comments[0].body = 'hi everyone'
# post.save #=> will save both post and comment and comment will have 'hi everyone'
# post.save # => will save both post and comment and comment will have 'hi everyone'
#
# In the above cases even without <tt>autosave</tt> option children got updated.
#
@ -99,7 +99,7 @@ module ActiveRecord
# post = Post.create(:title => 'ruby rocks')
# post.comments.create(:body => 'hello world')
# post.comments[0].body = 'hi everyone'
# post.save #=> will save both post and comment and comment will have 'hi everyone'
# post.save # => will save both post and comment and comment will have 'hi everyone'
#
# Destroying one of the associated models members, as part of the parent's
# save action, is as simple as marking it for destruction:

View file

@ -41,7 +41,7 @@ module ActiveRecord
# Returns the AggregateReflection object for the named +aggregation+ (use the symbol).
#
# Account.reflect_on_aggregation(:balance) #=> the balance AggregateReflection
# Account.reflect_on_aggregation(:balance) # => the balance AggregateReflection
#
def reflect_on_aggregation(aggregation)
reflections[aggregation].is_a?(AggregateReflection) ? reflections[aggregation] : nil

View file

@ -34,7 +34,7 @@ lifecycle methods that operate against a persistent store.
# Find a person with id = 1
ryan = Person.find(1)
Person.exists?(1) #=> true
Person.exists?(1) # => true
As you can see, the methods are quite similar to Active Record's methods for dealing with database
records. But rather than dealing directly with a database record, you're dealing with HTTP resources (which may or may not be database records).
@ -69,8 +69,8 @@ for a request for a single element, the XML of that item is expected in response
The XML document that is received is used to build a new object of type Person, with each
XML element becoming an attribute on the object.
ryan.is_a? Person #=> true
ryan.attribute1 #=> 'value1'
ryan.is_a? Person # => true
ryan.attribute1 # => 'value1'
Any complex element (one that contains other elements) becomes its own object:
@ -81,8 +81,8 @@ Any complex element (one that contains other elements) becomes its own object:
# for GET http://api.people.com:3000/people/1.xml
#
ryan = Person.find(1)
ryan.complex #=> <Person::Complex::xxxxx>
ryan.complex.attribute2 #=> 'value2'
ryan.complex # => <Person::Complex::xxxxx>
ryan.complex.attribute2 # => 'value2'
Collections can also be requested in a similar fashion
@ -96,8 +96,8 @@ Collections can also be requested in a similar fashion
# for GET http://api.people.com:3000/people.xml
#
people = Person.find(:all)
people.first #=> <Person::xxx 'first' => 'Ryan' ...>
people.last #=> <Person::xxx 'first' => 'Jim' ...>
people.first # => <Person::xxx 'first' => 'Ryan' ...>
people.last # => <Person::xxx 'first' => 'Jim' ...>
==== Create
@ -118,10 +118,10 @@ as the id of the ARes object.
# Response (201): Location: http://api.people.com:3000/people/2
#
ryan = Person.new(:first => 'Ryan')
ryan.new? #=> true
ryan.save #=> true
ryan.new? #=> false
ryan.id #=> 2
ryan.new? # => true
ryan.save # => true
ryan.new? # => false
ryan.id # => 2
==== Update
@ -139,9 +139,9 @@ server side was successful.
# is expected with code (204)
#
ryan = Person.find(1)
ryan.first #=> 'Ryan'
ryan.first # => 'Ryan'
ryan.first = 'Rizzle'
ryan.save #=> true
ryan.save # => true
==== Delete
@ -155,10 +155,10 @@ Destruction of a resource can be invoked as a class and instance method of the r
# is expected with response code (200)
#
ryan = Person.find(1)
ryan.destroy #=> true
ryan.exists? #=> false
Person.delete(2) #=> true
Person.exists?(2) #=> false
ryan.destroy # => true
ryan.exists? # => false
Person.delete(2) # => true
Person.exists?(2) # => false
You can find more usage information in the ActiveResource::Base documentation.

View file

@ -245,8 +245,8 @@ ActiveSupport.escape_html_entities_in_json from true to false to match previousl
* Add Array#in_groups which splits or iterates over the array in specified number of groups. #579. [Adrian Mugnolo] Example:
a = (1..10).to_a
a.in_groups(3) #=> [[1, 2, 3, 4], [5, 6, 7, nil], [8, 9, 10, nil]]
a.in_groups(3, false) #=> [[1, 2, 3, 4], [5, 6, 7], [8, 9, 10]]
a.in_groups(3) # => [[1, 2, 3, 4], [5, 6, 7, nil], [8, 9, 10, nil]]
a.in_groups(3, false) # => [[1, 2, 3, 4], [5, 6, 7], [8, 9, 10]]
* Fix TimeWithZone unmarshaling: coerce unmarshaled Time instances to utc, because Ruby's marshaling of Time instances doesn't respect the zone [Geoff Buesing]
@ -942,7 +942,7 @@ public for compatibility. [Jeremy Kemper]
* Enhance Symbol#to_proc so it works with list objects, such as multi-dimensional arrays. Closes #5295 [nov@yo.rim.or.jp]. Example:
{1 => "one", 2 => "two", 3 => "three"}.sort_by(&:first).map(&:last)
#=> ["one", "two", "three"]
# => ["one", "two", "three"]
* Added Hash.create_from_xml(string) which will create a hash from a XML string and even typecast if possible [David Heinemeier Hansson]. Example:

View file

@ -29,19 +29,19 @@ class Class
# In such cases, you don't want to do changes in places but use setters:
#
# Base.setting = []
# Base.setting #=> []
# Subclass.setting #=> []
# Base.setting # => []
# Subclass.setting # => []
#
# # Appending in child changes both parent and child because it is the same object:
# Subclass.setting << :foo
# Base.setting #=> [:foo]
# Subclass.setting #=> [:foo]
# Base.setting # => [:foo]
# Subclass.setting # => [:foo]
#
# # Use setters to not propagate changes:
# Base.setting = []
# Subclass.setting += [:foo]
# Base.setting #=> []
# Subclass.setting #=> [:foo]
# Base.setting # => []
# Subclass.setting # => [:foo]
#
# For convenience, a query method is defined as well:
#

View file

@ -12,8 +12,8 @@ require 'active_support/core_ext/array/extract_options'
# end
#
# Person.hair_colors = [:brown, :black, :blonde, :red]
# Person.hair_colors #=> [:brown, :black, :blonde, :red]
# Person.new.hair_colors #=> [:brown, :black, :blonde, :red]
# Person.hair_colors # => [:brown, :black, :blonde, :red]
# Person.new.hair_colors # => [:brown, :black, :blonde, :red]
#
# To opt out of the instance writer method, pass :instance_writer => false.
# To opt out of the instance reader method, pass :instance_reader => false.

View file

@ -22,8 +22,8 @@ end
# end
#
# Person.hair_colors = [:brown, :black, :blonde, :red]
# Person.hair_colors #=> [:brown, :black, :blonde, :red]
# Person.new.hair_colors #=> [:brown, :black, :blonde, :red]
# Person.hair_colors # => [:brown, :black, :blonde, :red]
# Person.new.hair_colors # => [:brown, :black, :blonde, :red]
#
# To opt out of the instance writer method, pass :instance_writer => false.
# To opt out of the instance reader method, pass :instance_reader => false.

View file

@ -371,7 +371,7 @@ The mass-assignment feature may become a problem, as it allows an attacker to se
<ruby>
def signup
params[:user] #=> {:name => “ow3ned”, :admin => true}
params[:user] # => {:name => “ow3ned”, :admin => true}
@user = User.new(params[:user])
end
</ruby>
@ -385,7 +385,7 @@ Mass-assignment saves you much work, because you don't have to set each value in
This will set the following parameters in the controller:
<ruby>
params[:user] #=> {:name => “ow3ned”, :admin => true}
params[:user] # => {:name => “ow3ned”, :admin => true}
</ruby>
So if you create a new user using mass-assignment, it may be too easy to become an administrator.
@ -423,11 +423,11 @@ attr_accessible :name
If you want to set a protected attribute, you will to have to assign it individually:
<ruby>
params[:user] #=> {:name => "ow3ned", :admin => true}
params[:user] # => {:name => "ow3ned", :admin => true}
@user = User.new(params[:user])
@user.admin #=> false # not mass-assigned
@user.admin # => false # not mass-assigned
@user.admin = true
@user.admin #=> true
@user.admin # => true
</ruby>
A more paranoid technique to protect your whole project would be to enforce that all models whitelist their accessible attributes. This can be easily achieved with a very simple initializer: