mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
overall cleanup of "#=>" and other minor details
This commit is contained in:
parent
22a47cb1ae
commit
63946cfb0e
11 changed files with 60 additions and 61 deletions
|
@ -9,7 +9,9 @@ module ActionController
|
|||
# Nested resources and/or namespaces are also supported, as illustrated in the example:
|
||||
#
|
||||
# polymorphic_url([:admin, @article, @comment])
|
||||
# #-> results in:
|
||||
#
|
||||
# results in:
|
||||
#
|
||||
# admin_article_comment_url(@article, @comment)
|
||||
#
|
||||
# == Usage within the framework
|
||||
|
@ -38,11 +40,8 @@ module ActionController
|
|||
#
|
||||
# Example usage:
|
||||
#
|
||||
# edit_polymorphic_path(@post)
|
||||
# #=> /posts/1/edit
|
||||
#
|
||||
# formatted_polymorphic_path([@post, :pdf])
|
||||
# #=> /posts/1.pdf
|
||||
# edit_polymorphic_path(@post) # => "/posts/1/edit"
|
||||
# formatted_polymorphic_path([@post, :pdf]) # => "/posts/1.pdf"
|
||||
module PolymorphicRoutes
|
||||
# Constructs a call to a named RESTful route for the given record and returns the
|
||||
# resulting URL string. For example:
|
||||
|
|
|
@ -324,13 +324,13 @@ module ActionView
|
|||
#
|
||||
# ==== Examples
|
||||
# label(:post, :title)
|
||||
# #=> <label for="post_title">Title</label>
|
||||
# # => <label for="post_title">Title</label>
|
||||
#
|
||||
# label(:post, :title, "A short title")
|
||||
# #=> <label for="post_title">A short title</label>
|
||||
# # => <label for="post_title">A short title</label>
|
||||
#
|
||||
# label(:post, :title, "A short title", :class => "title_label")
|
||||
# #=> <label for="post_title" class="title_label">A short title</label>
|
||||
# # => <label for="post_title" class="title_label">A short title</label>
|
||||
#
|
||||
def label(object_name, method, text = nil, options = {})
|
||||
InstanceTag.new(object_name, method, self, nil, options.delete(:object)).to_label_tag(text, options)
|
||||
|
|
|
@ -245,12 +245,14 @@ module ActiveRecord
|
|||
options.assert_valid_keys(CALCULATIONS_OPTIONS)
|
||||
end
|
||||
|
||||
# Converts a given key to the value that the database adapter returns as
|
||||
# a usable column name.
|
||||
# users.id #=> users_id
|
||||
# sum(id) #=> sum_id
|
||||
# count(distinct users.id) #=> count_distinct_users_id
|
||||
# count(*) #=> count_all
|
||||
# Converts the given keys to the value that the database adapter returns as
|
||||
# a usable column name:
|
||||
#
|
||||
# column_alias_for("users.id") # => "users_id"
|
||||
# column_alias_for("sum(id)") # => "sum_id"
|
||||
# column_alias_for("count(distinct users.id)") # => "count_distinct_users_id"
|
||||
# column_alias_for("count(*)") # => "count_all"
|
||||
# column_alias_for("count", "id") # => "count_id"
|
||||
def column_alias_for(*keys)
|
||||
connection.table_alias_for(keys.join(' ').downcase.gsub(/\*/, 'all').gsub(/\W+/, ' ').strip.gsub(/ +/, '_'))
|
||||
end
|
||||
|
|
|
@ -92,7 +92,7 @@ module ActiveRecord
|
|||
# Returns the human name of the column name.
|
||||
#
|
||||
# ===== Examples
|
||||
# Column.new('sales_stage', ...).human_name #=> 'Sales stage'
|
||||
# Column.new('sales_stage', ...).human_name # => 'Sales stage'
|
||||
def human_name
|
||||
Base.human_attribute_name(@name)
|
||||
end
|
||||
|
@ -350,28 +350,28 @@ module ActiveRecord
|
|||
# == Examples
|
||||
# # Assuming td is an instance of TableDefinition
|
||||
# td.column(:granted, :boolean)
|
||||
# #=> granted BOOLEAN
|
||||
# # granted BOOLEAN
|
||||
#
|
||||
# td.column(:picture, :binary, :limit => 2.megabytes)
|
||||
# #=> picture BLOB(2097152)
|
||||
# # => picture BLOB(2097152)
|
||||
#
|
||||
# td.column(:sales_stage, :string, :limit => 20, :default => 'new', :null => false)
|
||||
# #=> sales_stage VARCHAR(20) DEFAULT 'new' NOT NULL
|
||||
# # => sales_stage VARCHAR(20) DEFAULT 'new' NOT NULL
|
||||
#
|
||||
# def.column(:bill_gates_money, :decimal, :precision => 15, :scale => 2)
|
||||
# #=> bill_gates_money DECIMAL(15,2)
|
||||
# td.column(:bill_gates_money, :decimal, :precision => 15, :scale => 2)
|
||||
# # => bill_gates_money DECIMAL(15,2)
|
||||
#
|
||||
# def.column(:sensor_reading, :decimal, :precision => 30, :scale => 20)
|
||||
# #=> sensor_reading DECIMAL(30,20)
|
||||
# td.column(:sensor_reading, :decimal, :precision => 30, :scale => 20)
|
||||
# # => sensor_reading DECIMAL(30,20)
|
||||
#
|
||||
# # While <tt>:scale</tt> defaults to zero on most databases, it
|
||||
# # probably wouldn't hurt to include it.
|
||||
# def.column(:huge_integer, :decimal, :precision => 30)
|
||||
# #=> huge_integer DECIMAL(30)
|
||||
# td.column(:huge_integer, :decimal, :precision => 30)
|
||||
# # => huge_integer DECIMAL(30)
|
||||
#
|
||||
# == Short-hand examples
|
||||
#
|
||||
# Instead of calling column directly, you can also work with the short-hand definitions for the default types.
|
||||
# Instead of calling +column+ directly, you can also work with the short-hand definitions for the default types.
|
||||
# They use the type as the method name instead of as a parameter and allow for multiple columns to be defined
|
||||
# in a single statement.
|
||||
#
|
||||
|
|
|
@ -34,18 +34,18 @@ module ActiveResource
|
|||
# from REST web services.
|
||||
#
|
||||
# ryan = Person.new(:first => 'Ryan', :last => 'Daigle')
|
||||
# ryan.save #=> true
|
||||
# ryan.id #=> 2
|
||||
# Person.exists?(ryan.id) #=> true
|
||||
# ryan.exists? #=> true
|
||||
# ryan.save # => true
|
||||
# ryan.id # => 2
|
||||
# Person.exists?(ryan.id) # => true
|
||||
# ryan.exists? # => true
|
||||
#
|
||||
# ryan = Person.find(1)
|
||||
# # => Resource holding our newly created Person object
|
||||
# # Resource holding our newly created Person object
|
||||
#
|
||||
# ryan.first = 'Rizzle'
|
||||
# ryan.save #=> true
|
||||
# ryan.save # => true
|
||||
#
|
||||
# ryan.destroy #=> true
|
||||
# ryan.destroy # => true
|
||||
#
|
||||
# As you can see, these are very similar to Active Record's lifecycle methods for database records.
|
||||
# You can read more about each of these methods in their respective documentation.
|
||||
|
@ -156,8 +156,8 @@ module ActiveResource
|
|||
# then fail (with a <tt>false</tt> return value) and the validation errors can be accessed on the resource in question.
|
||||
#
|
||||
# ryan = Person.find(1)
|
||||
# ryan.first #=> ''
|
||||
# ryan.save #=> false
|
||||
# ryan.first # => ''
|
||||
# ryan.save # => false
|
||||
#
|
||||
# # When
|
||||
# # PUT http://api.people.com:3000/people/1.xml
|
||||
|
@ -167,8 +167,8 @@ module ActiveResource
|
|||
# # <errors type="array"><error>First cannot be empty</error></errors>
|
||||
# #
|
||||
#
|
||||
# ryan.errors.invalid?(:first) #=> true
|
||||
# ryan.errors.full_messages #=> ['First cannot be empty']
|
||||
# ryan.errors.invalid?(:first) # => true
|
||||
# ryan.errors.full_messages # => ['First cannot be empty']
|
||||
#
|
||||
# Learn more about Active Resource's validation features in the ActiveResource::Validations documentation.
|
||||
#
|
||||
|
|
|
@ -7,12 +7,12 @@ module ActiveResource
|
|||
# :member => { :promote => :put, :deactivate => :delete }
|
||||
# :collection => { :active => :get }
|
||||
#
|
||||
# This route set creates routes for the following http requests:
|
||||
# This route set creates routes for the following HTTP requests:
|
||||
#
|
||||
# POST /people/new/register.xml #=> PeopleController.register
|
||||
# PUT /people/1/promote.xml #=> PeopleController.promote with :id => 1
|
||||
# DELETE /people/1/deactivate.xml #=> PeopleController.deactivate with :id => 1
|
||||
# GET /people/active.xml #=> PeopleController.active
|
||||
# POST /people/new/register.xml # PeopleController.register
|
||||
# PUT /people/1/promote.xml # PeopleController.promote with :id => 1
|
||||
# DELETE /people/1/deactivate.xml # PeopleController.deactivate with :id => 1
|
||||
# GET /people/active.xml # PeopleController.active
|
||||
#
|
||||
# Using this module, Active Resource can use these custom REST methods just like the
|
||||
# standard methods.
|
||||
|
|
|
@ -17,17 +17,17 @@ module ActiveSupport #:nodoc:
|
|||
# string overrides can also be called through the +chars+ proxy.
|
||||
#
|
||||
# name = 'Claus Müller'
|
||||
# name.reverse #=> "rell??M sualC"
|
||||
# name.length #=> 13
|
||||
# name.reverse # => "rell??M sualC"
|
||||
# name.length # => 13
|
||||
#
|
||||
# name.chars.reverse.to_s #=> "rellüM sualC"
|
||||
# name.chars.length #=> 12
|
||||
# name.chars.reverse.to_s # => "rellüM sualC"
|
||||
# name.chars.length # => 12
|
||||
#
|
||||
#
|
||||
# All the methods on the chars proxy which normally return a string will return a Chars object. This allows
|
||||
# method chaining on the result of any of these methods.
|
||||
#
|
||||
# name.chars.reverse.length #=> 12
|
||||
# name.chars.reverse.length # => 12
|
||||
#
|
||||
# The Char object tries to be as interchangeable with String objects as possible: sorting and comparing between
|
||||
# String and Char work like expected. The bang! methods change the internal string representation in the Chars
|
||||
|
|
|
@ -59,7 +59,7 @@ module ActiveSupport #:nodoc:
|
|||
# Converts a Time object to a Date, dropping hour, minute, and second precision.
|
||||
#
|
||||
# my_time = Time.now # => Mon Nov 12 22:59:51 -0500 2007
|
||||
# my_time.to_date #=> Mon, 12 Nov 2007
|
||||
# my_time.to_date # => Mon, 12 Nov 2007
|
||||
#
|
||||
# your_time = Time.parse("1/13/2009 1:13:03 P.M.") # => Tue Jan 13 13:13:03 -0500 2009
|
||||
# your_time.to_date # => Tue, 13 Jan 2009
|
||||
|
|
|
@ -172,8 +172,8 @@ module Inflector
|
|||
# +titleize+ is also aliased as as +titlecase+.
|
||||
#
|
||||
# Examples:
|
||||
# "man from the boondocks".titleize #=> "Man From The Boondocks"
|
||||
# "x-men: the last stand".titleize #=> "X Men: The Last Stand"
|
||||
# "man from the boondocks".titleize # => "Man From The Boondocks"
|
||||
# "x-men: the last stand".titleize # => "X Men: The Last Stand"
|
||||
def titleize(word)
|
||||
humanize(underscore(word)).gsub(/\b('?[a-z])/) { $1.capitalize }
|
||||
end
|
||||
|
|
|
@ -10,7 +10,7 @@ module ActiveSupport::Multibyte #:nodoc:
|
|||
# String methods are proxied through the Chars object, and can be accessed through the +chars+ method. Methods
|
||||
# which would normally return a String object now return a Chars object so methods can be chained.
|
||||
#
|
||||
# "The Perfect String ".chars.downcase.strip.normalize #=> "the perfect string"
|
||||
# "The Perfect String ".chars.downcase.strip.normalize # => "the perfect string"
|
||||
#
|
||||
# Chars objects are perfectly interchangeable with String objects as long as no explicit class checks are made.
|
||||
# If certain methods do explicitly check the class, call +to_s+ before you pass chars objects to them.
|
||||
|
|
|
@ -147,13 +147,11 @@ module ActiveSupport::Multibyte::Handlers #:nodoc:
|
|||
#
|
||||
# s = "Müller"
|
||||
# s.chars[2] = "e" # Replace character with offset 2
|
||||
# s
|
||||
# #=> "Müeler"
|
||||
# s # => "Müeler"
|
||||
#
|
||||
# s = "Müller"
|
||||
# s.chars[1, 2] = "ö" # Replace 2 characters at character offset 1
|
||||
# s
|
||||
# #=> "Möler"
|
||||
# s # => "Möler"
|
||||
def []=(str, *args)
|
||||
replace_by = args.pop
|
||||
# Indexed replace with regular expressions already works
|
||||
|
@ -183,10 +181,10 @@ module ActiveSupport::Multibyte::Handlers #:nodoc:
|
|||
# Example:
|
||||
#
|
||||
# "¾ cup".chars.rjust(8).to_s
|
||||
# #=> " ¾ cup"
|
||||
# # => " ¾ cup"
|
||||
#
|
||||
# "¾ cup".chars.rjust(8, " ").to_s # Use non-breaking whitespace
|
||||
# #=> " ¾ cup"
|
||||
# # => " ¾ cup"
|
||||
def rjust(str, integer, padstr=' ')
|
||||
justify(str, integer, :right, padstr)
|
||||
end
|
||||
|
@ -196,10 +194,10 @@ module ActiveSupport::Multibyte::Handlers #:nodoc:
|
|||
# Example:
|
||||
#
|
||||
# "¾ cup".chars.rjust(8).to_s
|
||||
# #=> "¾ cup "
|
||||
# # => "¾ cup "
|
||||
#
|
||||
# "¾ cup".chars.rjust(8, " ").to_s # Use non-breaking whitespace
|
||||
# #=> "¾ cup "
|
||||
# # => "¾ cup "
|
||||
def ljust(str, integer, padstr=' ')
|
||||
justify(str, integer, :left, padstr)
|
||||
end
|
||||
|
@ -209,10 +207,10 @@ module ActiveSupport::Multibyte::Handlers #:nodoc:
|
|||
# Example:
|
||||
#
|
||||
# "¾ cup".chars.center(8).to_s
|
||||
# #=> " ¾ cup "
|
||||
# # => " ¾ cup "
|
||||
#
|
||||
# "¾ cup".chars.center(8, " ").to_s # Use non-breaking whitespace
|
||||
# #=> " ¾ cup "
|
||||
# # => " ¾ cup "
|
||||
def center(str, integer, padstr=' ')
|
||||
justify(str, integer, :center, padstr)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue