From 3a6ffbbe42688f40edc8e0a12d0f556ef3720b9d Mon Sep 17 00:00:00 2001 From: Nick Novitski Date: Wed, 9 May 2012 13:20:19 -0700 Subject: remove inappropriate comma A qualifying clause beginning with words like "as", "if", or "although" should have a comma separating it from any following clauses in a sentence, but should not have a comma immediately after the beginning word, unless it is to separate a third, non-essential clause. Example 1: "Although I would quite like to go to lunch with you, I find myself instead writing a detailed commit message to justify a single-character documentation change." Example 2: "Despite, as you might well imagine, wishing I hadn't even noticed it in the first place, I still felt the error was worth correcting." --- guides/source/security.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/source/security.textile b/guides/source/security.textile index ac64b82bf6..ac55d60368 100644 --- a/guides/source/security.textile +++ b/guides/source/security.textile @@ -627,7 +627,7 @@ h4. Whitelists versus Blacklists -- _When sanitizing, protecting or verifying something, whitelists over blacklists._ -A blacklist can be a list of bad e-mail addresses, non-public actions or bad HTML tags. This is opposed to a whitelist which lists the good e-mail addresses, public actions, good HTML tags and so on. Although, sometimes it is not possible to create a whitelist (in a SPAM filter, for example), _(highlight)prefer to use whitelist approaches_: +A blacklist can be a list of bad e-mail addresses, non-public actions or bad HTML tags. This is opposed to a whitelist which lists the good e-mail addresses, public actions, good HTML tags and so on. Although sometimes it is not possible to create a whitelist (in a SPAM filter, for example), _(highlight)prefer to use whitelist approaches_: * Use before_filter :only => [...] instead of :except => [...]. This way you don't forget to turn it off for newly added actions. * Use attr_accessible instead of attr_protected. See the mass-assignment section for details -- cgit v1.2.3 From 6cbe8dab1e64d42eb376137366b48f1e20f9ddb9 Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Thu, 10 May 2012 02:09:59 -0500 Subject: deleting empty lines in docs parts --- activesupport/lib/active_support/callbacks.rb | 8 -------- 1 file changed, 8 deletions(-) diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb index cbeba3139a..1972d439ed 100644 --- a/activesupport/lib/active_support/callbacks.rb +++ b/activesupport/lib/active_support/callbacks.rb @@ -54,7 +54,6 @@ module ActiveSupport # saving... # - save # saved - # module Callbacks extend Concern @@ -73,7 +72,6 @@ module ActiveSupport # run_callbacks :save do # save # end - # def run_callbacks(kind, key = nil, &block) #TODO: deprecate key argument runner_name = self.class.__define_callbacks(kind, self) @@ -199,7 +197,6 @@ module ActiveSupport # yield self # end # end - # def define_conditional_callback name = "_conditional_callback_#{@kind}_#{next_id}" @klass.class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1 @@ -253,7 +250,6 @@ module ActiveSupport # Objects:: # a method is created that calls the before_foo method # on the object. - # def _compile_filter(filter) method_name = "_callback_#{@kind}_#{next_id}" case filter @@ -405,7 +401,6 @@ module ActiveSupport # will be called only when it returns a false value. # * :prepend - If true, the callback will be prepended to the existing # chain rather than appended. - # def set_callback(name, *filter_list, &block) mapped = nil @@ -430,7 +425,6 @@ module ActiveSupport # class Writer < Person # skip_callback :validate, :before, :check_membership, :if => lambda { self.age > 18 } # end - # def skip_callback(name, *filter_list, &block) __update_callbacks(name, filter_list, block) do |target, chain, type, filters, options| filters.each do |filter| @@ -449,7 +443,6 @@ module ActiveSupport end # Remove all set callbacks for the given event. - # def reset_callbacks(symbol) callbacks = send("_#{symbol}_callbacks") @@ -530,7 +523,6 @@ module ActiveSupport # define_callbacks :save, :scope => [:name] # # would call Audit#save. - # def define_callbacks(*callbacks) config = callbacks.last.is_a?(Hash) ? callbacks.pop : {} callbacks.each do |callback| -- cgit v1.2.3 From c8f5a216df7d14463027425b53968d7f7023bf85 Mon Sep 17 00:00:00 2001 From: Ben Wilhelm Date: Thu, 10 May 2012 11:15:32 -0700 Subject: Modified template in sample is new.html.erb, not index.html.erb --- guides/source/getting_started.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/source/getting_started.textile b/guides/source/getting_started.textile index 947abd7ba0..1e9bd1f144 100644 --- a/guides/source/getting_started.textile +++ b/guides/source/getting_started.textile @@ -717,7 +717,7 @@ If you reload try to save a post without a title, Rails will send you back to the form, but that's not very useful. You need to tell the user that something went wrong. To do that, you'll modify -+app/views/posts/index.html.erb+ to check for error messages: ++app/views/posts/new.html.erb+ to check for error messages: <%= form_for :post, :url => { :action => :create } do |f| %> -- cgit v1.2.3 From 1065ef8fd3ad499feec01b39292ee435c1f71c13 Mon Sep 17 00:00:00 2001 From: Edward Tsech Date: Fri, 11 May 2012 11:11:41 +0200 Subject: Fix copypaste. [ci skip] --- activesupport/test/core_ext/hash_ext_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index 1cd10eb6e2..822fcbc53e 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -491,11 +491,11 @@ class HashExtTest < ActiveSupport::TestCase original = { :a => 'x', :b => 'y', :c => 10 } expected = { :a => 'x', :b => 'y' } - # Should return a new hash with only the given keys. + # Should return a new hash without the given keys. assert_equal expected, original.except(:c) assert_not_equal expected, original - # Should replace the hash with only the given keys. + # Should replace the hash without the given keys. assert_equal expected, original.except!(:c) assert_equal expected, original end -- cgit v1.2.3 From c9a4e65217cc0711f264410484d23fb8b519b660 Mon Sep 17 00:00:00 2001 From: Egor Homakov Date: Fri, 11 May 2012 14:48:02 +0400 Subject: Update guides/source/configuring.textile --- guides/source/configuring.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/source/configuring.textile b/guides/source/configuring.textile index c4e54348d4..bed8ce3eb6 100644 --- a/guides/source/configuring.textile +++ b/guides/source/configuring.textile @@ -448,7 +448,7 @@ There are a few configuration options available in Active Support: * +config.active_support.bare+ enables or disables the loading of +active_support/all+ when booting Rails. Defaults to +nil+, which means +active_support/all+ is loaded. -* +config.active_support.escape_html_entities_in_json+ enables or disables the escaping of HTML entities in JSON serialization. Defaults to +true+. +* +config.active_support.escape_html_entities_in_json+ enables or disables the escaping of HTML entities in JSON serialization. Defaults to +false+. * +config.active_support.use_standard_json_time_format+ enables or disables serializing dates to ISO 8601 format. Defaults to +false+. -- cgit v1.2.3 From d4f4b858d3c493ea74a1e4ed8ed6566bfa4c7e27 Mon Sep 17 00:00:00 2001 From: Egor Homakov Date: Fri, 11 May 2012 15:40:03 +0400 Subject: Update guides/source/configuring.textile --- guides/source/configuring.textile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guides/source/configuring.textile b/guides/source/configuring.textile index bed8ce3eb6..b2c9300034 100644 --- a/guides/source/configuring.textile +++ b/guides/source/configuring.textile @@ -450,7 +450,7 @@ There are a few configuration options available in Active Support: * +config.active_support.escape_html_entities_in_json+ enables or disables the escaping of HTML entities in JSON serialization. Defaults to +false+. -* +config.active_support.use_standard_json_time_format+ enables or disables serializing dates to ISO 8601 format. Defaults to +false+. +* +config.active_support.use_standard_json_time_format+ enables or disables serializing dates to ISO 8601 format. Defaults to +true+. * +ActiveSupport::BufferedLogger.silencer+ is set to +false+ to disable the ability to silence logging in a block. The default is +true+. -- cgit v1.2.3 From 24e4bc31b98a773924887137afb6f415ef1c0a9e Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Fri, 11 May 2012 14:47:26 +0200 Subject: Move HTTP Token auth docs above the Token module --- .../action_controller/metal/http_authentication.rb | 86 +++++++++++----------- 1 file changed, 44 insertions(+), 42 deletions(-) diff --git a/actionpack/lib/action_controller/metal/http_authentication.rb b/actionpack/lib/action_controller/metal/http_authentication.rb index 87225d74c1..57bb0e2a32 100644 --- a/actionpack/lib/action_controller/metal/http_authentication.rb +++ b/actionpack/lib/action_controller/metal/http_authentication.rb @@ -2,8 +2,9 @@ require 'base64' require 'active_support/core_ext/object/blank' module ActionController + # Makes it dead easy to do HTTP Basic, Digest and Token authentication. module HttpAuthentication - # Makes it dead easy to do HTTP \Basic and \Digest authentication. + # Makes it dead easy to do HTTP \Basic authentication. # # === Simple \Basic example # @@ -60,47 +61,6 @@ module ActionController # # assert_equal 200, status # end - # - # === Simple \Digest example - # - # require 'digest/md5' - # class PostsController < ApplicationController - # REALM = "SuperSecret" - # USERS = {"dhh" => "secret", #plain text password - # "dap" => Digest::MD5.hexdigest(["dap",REALM,"secret"].join(":"))} #ha1 digest password - # - # before_filter :authenticate, :except => [:index] - # - # def index - # render :text => "Everyone can see me!" - # end - # - # def edit - # render :text => "I'm only accessible if you know the password" - # end - # - # private - # def authenticate - # authenticate_or_request_with_http_digest(REALM) do |username| - # USERS[username] - # end - # end - # end - # - # === Notes - # - # The +authenticate_or_request_with_http_digest+ block must return the user's password - # or the ha1 digest hash so the framework can appropriately hash to check the user's - # credentials. Returning +nil+ will cause authentication to fail. - # - # Storing the ha1 hash: MD5(username:realm:password), is better than storing a plain password. If - # the password file or database is compromised, the attacker would be able to use the ha1 hash to - # authenticate as the user at this +realm+, but would not have the user's password to try using at - # other sites. - # - # In rare instances, web servers or front proxies strip authorization headers before - # they reach your application. You can debug this situation by logging all environment - # variables, and check for HTTP_AUTHORIZATION, amongst others. module Basic extend self @@ -155,6 +115,48 @@ module ActionController end end + # Makes it dead easy to do HTTP \Digest authentication. + # + # === Simple \Digest example + # + # require 'digest/md5' + # class PostsController < ApplicationController + # REALM = "SuperSecret" + # USERS = {"dhh" => "secret", #plain text password + # "dap" => Digest::MD5.hexdigest(["dap",REALM,"secret"].join(":"))} #ha1 digest password + # + # before_filter :authenticate, :except => [:index] + # + # def index + # render :text => "Everyone can see me!" + # end + # + # def edit + # render :text => "I'm only accessible if you know the password" + # end + # + # private + # def authenticate + # authenticate_or_request_with_http_digest(REALM) do |username| + # USERS[username] + # end + # end + # end + # + # === Notes + # + # The +authenticate_or_request_with_http_digest+ block must return the user's password + # or the ha1 digest hash so the framework can appropriately hash to check the user's + # credentials. Returning +nil+ will cause authentication to fail. + # + # Storing the ha1 hash: MD5(username:realm:password), is better than storing a plain password. If + # the password file or database is compromised, the attacker would be able to use the ha1 hash to + # authenticate as the user at this +realm+, but would not have the user's password to try using at + # other sites. + # + # In rare instances, web servers or front proxies strip authorization headers before + # they reach your application. You can debug this situation by logging all environment + # variables, and check for HTTP_AUTHORIZATION, amongst others. module Digest extend self -- cgit v1.2.3 From bd2b1c126bae98d93426915e036513dc0137ce25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hrvoje=20=C5=A0imi=C4=87?= Date: Fri, 11 May 2012 16:09:10 +0200 Subject: missing 'with' --- activerecord/lib/active_record/aggregations.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/aggregations.rb b/activerecord/lib/active_record/aggregations.rb index a4db627535..c7a329d74d 100644 --- a/activerecord/lib/active_record/aggregations.rb +++ b/activerecord/lib/active_record/aggregations.rb @@ -71,7 +71,7 @@ module ActiveRecord # Now it's possible to access attributes from the database through the value objects instead. If # you choose to name the composition the same as the attribute's name, it will be the only way to # access that attribute. That's the case with our +balance+ attribute. You interact with the value - # objects just like you would any other attribute, though: + # objects just like you would with any other attribute: # # customer.balance = Money.new(20) # sets the Money value object and the attribute # customer.balance # => Money value object -- cgit v1.2.3 From 1b956700ee61e8cc5fab140b38d702767e3d03f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hrvoje=20=C5=A0imi=C4=87?= Date: Fri, 11 May 2012 16:27:21 +0200 Subject: better wording --- activerecord/lib/active_record/nested_attributes.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/activerecord/lib/active_record/nested_attributes.rb b/activerecord/lib/active_record/nested_attributes.rb index 32a1dae6bc..95a2ddcc11 100644 --- a/activerecord/lib/active_record/nested_attributes.rb +++ b/activerecord/lib/active_record/nested_attributes.rb @@ -19,10 +19,10 @@ module ActiveRecord # = Active Record Nested Attributes # # Nested attributes allow you to save attributes on associated records - # through the parent. By default nested attribute updating is turned off, - # you can enable it using the accepts_nested_attributes_for class method. - # When you enable nested attributes an attribute writer is defined on - # the model. + # through the parent. By default nested attribute updating is turned off + # and you can enable it using the accepts_nested_attributes_for class + # method. When you enable nested attributes an attribute writer is + # defined on the model. # # The attribute writer is named after the association, which means that # in the following example, two new methods are added to your model: -- cgit v1.2.3 From 7ce4ce33c7c3229752c51dd92ca9d758ec452fc1 Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Fri, 11 May 2012 10:51:36 -0500 Subject: added docs to String#at --- .../lib/active_support/core_ext/string/access.rb | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/activesupport/lib/active_support/core_ext/string/access.rb b/activesupport/lib/active_support/core_ext/string/access.rb index 23aaee9c43..8a922a7069 100644 --- a/activesupport/lib/active_support/core_ext/string/access.rb +++ b/activesupport/lib/active_support/core_ext/string/access.rb @@ -1,6 +1,31 @@ require 'active_support/multibyte' class String + # If you pass a single Fixnum, returns a substring of one character at that + # position. The first character of the string is at position 0, the next at + # position 1, and so on. If a range is supplied, a substring containing + # characters at offsets given by the range is returned. In both cases, if an + # offset is negative, it is counted from the end of the string. Returns nil + # if the initial offset falls outside the string. Returns an empty string if + # the beginning of the range is greater than the end of the string. + # + # str = "hello" + # str.at(0) #=> "h" + # str.at(1..3) #=> "ell" + # str.at(-2) #=> "l" + # str.at(-2..-1) #=> "lo" + # str.at(5) #=> nil + # str.at(5..-1) #=> "" + # + # If a Regexp is given, the matching portion of the string is returned. + # If a String is given, that given string is returned if it occurs in + # the string. In both cases, nil is returned if there is no match. + # + # str = "hello" + # str.at(/lo/) #=> "lo" + # str.at(/ol/) #=> nil + # str.at("lo") #=> "lo" + # str.at("ol") #=> nil def at(position) self[position] end -- cgit v1.2.3 From 1004ccc84b16a78d9aa3180e57dda278002fe53e Mon Sep 17 00:00:00 2001 From: Eric Carty-Fickes Date: Fri, 11 May 2012 11:12:32 -0500 Subject: Clarify expire_action with namespaced controllers --- guides/source/caching_with_rails.textile | 36 ++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/guides/source/caching_with_rails.textile b/guides/source/caching_with_rails.textile index e455b504ce..34a100cd3a 100644 --- a/guides/source/caching_with_rails.textile +++ b/guides/source/caching_with_rails.textile @@ -229,6 +229,42 @@ class ProductsController < ActionController end +Sometimes it is necessary to disambiguate the controller when you call +expire_action+, such as when there are two identically named controllers in separate namespaces: + + +class ProductsController < ActionController + caches_action :index + + def index + @products = Product.all + end +end + +module Admin + class ProductsController < ActionController + cache_sweeper :product_sweeper + + def new + @product = Product.new + end + + def create + @product = Product.create(params[:product]) + end + end +end + +class ProductSweeper < ActionController::Caching::Sweeper + observe Product + + def after_create(product) + expire_action(:controller => '/products', :action => 'index') + end +end + + +Note the use of '/products' here rather than 'products'. If you wanted to expire an action cache for the +Admin::ProductsController+, you would use 'admin/products' instead. + h4. SQL Caching Query caching is a Rails feature that caches the result set returned by each query so that if Rails encounters the same query again for that request, it will use the cached result set as opposed to running the query against the database again. -- cgit v1.2.3 From 315350847f5089fa2b314b00d485e5121f5622d4 Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Fri, 11 May 2012 11:35:26 -0500 Subject: added docs to String#to --- activesupport/lib/active_support/core_ext/string/access.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/activesupport/lib/active_support/core_ext/string/access.rb b/activesupport/lib/active_support/core_ext/string/access.rb index 8a922a7069..5cdf42ce4b 100644 --- a/activesupport/lib/active_support/core_ext/string/access.rb +++ b/activesupport/lib/active_support/core_ext/string/access.rb @@ -34,6 +34,19 @@ class String self[position..-1] end + # Returns the beginning of the string up to position. If the position is + # negative, it is counted from the end of the string. + # + # str = "hello" + # str.to(0) #=> "h" + # str.to(3) #=> "hell" + # str.to(-2) #=> "hell" + # + # You can mix it with +from+ method and do fun things like: + # + # str = "hello" + # str.from(0).to(-1) #=> "hello" + # str.from(1).to(-2) #=> "ell" def to(position) self[0..position] end -- cgit v1.2.3 From 0822dc01f68eb262274fbedcf97a224e6457ff3b Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Fri, 11 May 2012 11:41:22 -0500 Subject: improve String#to docs --- activesupport/lib/active_support/core_ext/string/access.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/string/access.rb b/activesupport/lib/active_support/core_ext/string/access.rb index 5cdf42ce4b..9494a9b69d 100644 --- a/activesupport/lib/active_support/core_ext/string/access.rb +++ b/activesupport/lib/active_support/core_ext/string/access.rb @@ -34,8 +34,8 @@ class String self[position..-1] end - # Returns the beginning of the string up to position. If the position is - # negative, it is counted from the end of the string. + # Returns a substring from the beginning of the string to the given position. + # If the position is negative, it is counted from the end of the string. # # str = "hello" # str.to(0) #=> "h" -- cgit v1.2.3 From 07045fa919b4787d8ec458a1594f62cdedaf1b06 Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Fri, 11 May 2012 11:47:40 -0500 Subject: added docs to String#from --- activesupport/lib/active_support/core_ext/string/access.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/activesupport/lib/active_support/core_ext/string/access.rb b/activesupport/lib/active_support/core_ext/string/access.rb index 9494a9b69d..1436d43be6 100644 --- a/activesupport/lib/active_support/core_ext/string/access.rb +++ b/activesupport/lib/active_support/core_ext/string/access.rb @@ -30,6 +30,19 @@ class String self[position] end + # Returns a substring from the given position to the end of the string. + # If the position is negative, it is counted from the end of the string. + # + # str = "hello" + # str.from(0) #=> "hello" + # str.from(3) #=> "lo" + # str.from(-2) #=> "lo" + # + # You can mix it with +to+ method and do fun things like: + # + # str = "hello" + # str.from(0).to(-1) #=> "hello" + # str.from(1).to(-2) #=> "ell" def from(position) self[position..-1] end -- cgit v1.2.3 From 84784b4f234c0f21096202309805c3c304901baa Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Fri, 11 May 2012 12:20:57 -0500 Subject: added docs to String#first --- activesupport/lib/active_support/core_ext/string/access.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/activesupport/lib/active_support/core_ext/string/access.rb b/activesupport/lib/active_support/core_ext/string/access.rb index 1436d43be6..43024fb012 100644 --- a/activesupport/lib/active_support/core_ext/string/access.rb +++ b/activesupport/lib/active_support/core_ext/string/access.rb @@ -64,6 +64,17 @@ class String self[0..position] end + # Returns the first character of the string. If a limit is supplied, + # returns a substring from the beginning of the string to the given + # limit. If the given limit is greater than or equal to the string + # length, returns it self. + # + # str = "hello" + # str.first #=> "h" + # str.first(1) #=> "h" + # str.first(2) #=> "he" + # str.first(0) #=> "" + # str.first(6) #=> "hello" def first(limit = 1) if limit == 0 '' -- cgit v1.2.3 From 074359dfa8d9e16058de4bd6375b2438fef3de83 Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Fri, 11 May 2012 12:24:45 -0500 Subject: fix typo in String#first --- activesupport/lib/active_support/core_ext/string/access.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activesupport/lib/active_support/core_ext/string/access.rb b/activesupport/lib/active_support/core_ext/string/access.rb index 43024fb012..9bb0c597b2 100644 --- a/activesupport/lib/active_support/core_ext/string/access.rb +++ b/activesupport/lib/active_support/core_ext/string/access.rb @@ -67,7 +67,7 @@ class String # Returns the first character of the string. If a limit is supplied, # returns a substring from the beginning of the string to the given # limit. If the given limit is greater than or equal to the string - # length, returns it self. + # length, returns self. # # str = "hello" # str.first #=> "h" -- cgit v1.2.3 From b2e9d33515eb858507cfab8e15eb4a9e049a433a Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Fri, 11 May 2012 12:56:53 -0500 Subject: improve String#first docs --- activesupport/lib/active_support/core_ext/string/access.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/string/access.rb b/activesupport/lib/active_support/core_ext/string/access.rb index 9bb0c597b2..baa5b84db6 100644 --- a/activesupport/lib/active_support/core_ext/string/access.rb +++ b/activesupport/lib/active_support/core_ext/string/access.rb @@ -64,10 +64,9 @@ class String self[0..position] end - # Returns the first character of the string. If a limit is supplied, - # returns a substring from the beginning of the string to the given - # limit. If the given limit is greater than or equal to the string - # length, returns self. + # Returns the first character. If a limit is supplied, returns a substring + # from the beginning of the string until it reaches the limit value. If the + # given limit is greater than or equal to the string length, returns self. # # str = "hello" # str.first #=> "h" -- cgit v1.2.3 From ed116eda053e8cccb5dda1c4724f8609eceaa90f Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Fri, 11 May 2012 13:11:06 -0500 Subject: added docs to String#last --- activesupport/lib/active_support/core_ext/string/access.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/activesupport/lib/active_support/core_ext/string/access.rb b/activesupport/lib/active_support/core_ext/string/access.rb index baa5b84db6..76b30b4c19 100644 --- a/activesupport/lib/active_support/core_ext/string/access.rb +++ b/activesupport/lib/active_support/core_ext/string/access.rb @@ -84,6 +84,16 @@ class String end end + # Returns the last character of the string. If a limit is supplied, returns a substring + # from the end of the string until it reaches the limit value (counting backwards). If + # the given limit is greater than or equal to the string length, returns self. + # + # str = "hello" + # str.last #=> "h" + # str.last(1) #=> "h" + # str.last(2) #=> "lo" + # str.last(0) #=> "" + # str.last(6) #=> "hello" def last(limit = 1) if limit == 0 '' -- cgit v1.2.3 From 53ef85dae8081e81f7dbb1f09a6150777f509cd4 Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Fri, 11 May 2012 13:16:35 -0500 Subject: fix String#last example --- activesupport/lib/active_support/core_ext/string/access.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activesupport/lib/active_support/core_ext/string/access.rb b/activesupport/lib/active_support/core_ext/string/access.rb index 76b30b4c19..2ebfd48818 100644 --- a/activesupport/lib/active_support/core_ext/string/access.rb +++ b/activesupport/lib/active_support/core_ext/string/access.rb @@ -89,7 +89,7 @@ class String # the given limit is greater than or equal to the string length, returns self. # # str = "hello" - # str.last #=> "h" + # str.last #=> "o" # str.last(1) #=> "h" # str.last(2) #=> "lo" # str.last(0) #=> "" -- cgit v1.2.3 From 39c483fec56b98b0cdb11b705cd7e63b43d60a64 Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Fri, 11 May 2012 13:18:00 -0500 Subject: fix String#last example --- activesupport/lib/active_support/core_ext/string/access.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activesupport/lib/active_support/core_ext/string/access.rb b/activesupport/lib/active_support/core_ext/string/access.rb index 2ebfd48818..5c32a2453d 100644 --- a/activesupport/lib/active_support/core_ext/string/access.rb +++ b/activesupport/lib/active_support/core_ext/string/access.rb @@ -90,7 +90,7 @@ class String # # str = "hello" # str.last #=> "o" - # str.last(1) #=> "h" + # str.last(1) #=> "o" # str.last(2) #=> "lo" # str.last(0) #=> "" # str.last(6) #=> "hello" -- cgit v1.2.3 From a0d9b7903588cd988c8c9b4164494c792344f43e Mon Sep 17 00:00:00 2001 From: Scott Johnson <7.scott.j@gmail.com> Date: Fri, 11 May 2012 13:42:37 -0500 Subject: update engines guide to show how to have an engine's ApplicationController inherit from the main application's ApplicationController --- guides/source/engines.textile | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/guides/source/engines.textile b/guides/source/engines.textile index 71bcf6b713..b94ede44c4 100644 --- a/guides/source/engines.textile +++ b/guides/source/engines.textile @@ -448,6 +448,8 @@ rake db:migrate SCOPE=blorgh VERSION=0 h4. Using a class provided by the application +h5. Using a model provided by the application + When an engine is created, it may want to use specific classes from an application to provide links between the pieces of the engine and the pieces of the application. In the case of the +blorgh+ engine, making posts and comments have authors would make a lot of sense. Usually, an application would have a +User+ class that would provide the objects that would represent the posts' and comments' authors, but there could be a case where the application calls this class something different, such as +Person+. It's because of this reason that the engine should not hardcode the associations to be exactly for a +User+ class, but should allow for some flexibility around what the class is called. @@ -544,6 +546,19 @@ end Now instead of the ugly Ruby object output the author's name will be displayed. +h5. Using a controller provided by the application + +Because Rails controllers generally share code for for things like authentication and accessing session variables, by default they inherit from ApplicationController. Rails engines, however are scoped to run independently from the main application, so each engine gets a scoped ApplicationController. This namespace prevents code collisions, but often engine controllers should access methods in the main application's ApplicationController. An easy way to provide this acess is to change the engine's scoped ApplicationController to inherit from the main application's ApplicationController. For our Blorgh engine this would be done by changing +app/controllers/blorgh/application_controller.rb+ to look like: + + + class Blorgh::ApplicationController < ApplicationController + end + + +By default, the engine's controllers inherit from Blorgh::ApplicationController. So, after making this change they will have access to the main applications ApplicationController as though they were part of the main application. + +This change does require that the engine is run from a Rails application that has an ApplicationController. + h4. Configuring an engine This section covers firstly how you can make the +user_class+ setting of the Blorgh engine configurable, followed by general configuration tips for the engine. -- cgit v1.2.3 From ef440bb0c3378a04300c592ec8432d26afc6ad1d Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Fri, 11 May 2012 16:21:32 -0500 Subject: remove unnecessary 'examples' noise --- activesupport/lib/active_support/core_ext/string/filters.rb | 1 - activesupport/lib/active_support/core_ext/string/inflections.rb | 6 ------ activesupport/lib/active_support/core_ext/string/output_safety.rb | 2 -- 3 files changed, 9 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/string/filters.rb b/activesupport/lib/active_support/core_ext/string/filters.rb index 32a37296d5..2478f42290 100644 --- a/activesupport/lib/active_support/core_ext/string/filters.rb +++ b/activesupport/lib/active_support/core_ext/string/filters.rb @@ -5,7 +5,6 @@ class String # the string, and then changing remaining consecutive whitespace # groups into one space each. # - # Examples: # %{ Multi-line # string }.squish # => "Multi-line string" # " foo bar \n \t boo".squish # => "foo bar boo" diff --git a/activesupport/lib/active_support/core_ext/string/inflections.rb b/activesupport/lib/active_support/core_ext/string/inflections.rb index 049ffe7986..070bfd7af6 100644 --- a/activesupport/lib/active_support/core_ext/string/inflections.rb +++ b/activesupport/lib/active_support/core_ext/string/inflections.rb @@ -13,7 +13,6 @@ class String # the singular form will be returned if count == 1. # For any other value of +count+ the plural will be returned. # - # ==== Examples # 'post'.pluralize # => "posts" # 'octopus'.pluralize # => "octopi" # 'sheep'.pluralize # => "sheep" @@ -46,7 +45,6 @@ class String # in the string. It raises a NameError when the name is not in CamelCase # or is not initialized. See ActiveSupport::Inflector.constantize # - # Examples # 'Module'.constantize # => Module # 'Class'.constantize # => Class # 'blargle'.constantize # => NameError: wrong constant name blargle @@ -58,7 +56,6 @@ class String # in the string. It returns nil when the name is not in CamelCase # or is not initialized. See ActiveSupport::Inflector.safe_constantize # - # Examples # 'Module'.safe_constantize # => Module # 'Class'.safe_constantize # => Class # 'blargle'.safe_constantize # => nil @@ -140,8 +137,6 @@ class String # Replaces special characters in a string so that it may be used as part of a 'pretty' URL. # - # ==== Examples - # # class Person # def to_param # "#{id}-#{name.parameterize}" @@ -194,7 +189,6 @@ class String # +separate_class_name_and_id_with_underscore+ sets whether # the method should put '_' between the name and 'id'. # - # Examples # 'Message'.foreign_key # => "message_id" # 'Message'.foreign_key(false) # => "messageid" # 'Admin::Post'.foreign_key # => "post_id" diff --git a/activesupport/lib/active_support/core_ext/string/output_safety.rb b/activesupport/lib/active_support/core_ext/string/output_safety.rb index 215ba87ca9..6bda970e40 100644 --- a/activesupport/lib/active_support/core_ext/string/output_safety.rb +++ b/activesupport/lib/active_support/core_ext/string/output_safety.rb @@ -14,7 +14,6 @@ class ERB # In your ERB templates, use this method to escape any unsafe content. For example: # <%=h @person.name %> # - # ==== Example: # puts html_escape('is a > 0 & a < 10?') # # => is a > 0 & a < 10? def html_escape(s) @@ -37,7 +36,6 @@ class ERB # A utility method for escaping HTML without affecting existing escaped entities. # - # ==== Examples # html_escape_once('1 < 2 & 3') # # => "1 < 2 & 3" # -- cgit v1.2.3 From 7bf6edf819adf48b253dce7673ec82cda821646b Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Fri, 11 May 2012 16:42:23 -0500 Subject: added examples to String#exclude? --- activesupport/lib/active_support/core_ext/string/exclude.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/activesupport/lib/active_support/core_ext/string/exclude.rb b/activesupport/lib/active_support/core_ext/string/exclude.rb index 5e184ec1b3..114bcb87f0 100644 --- a/activesupport/lib/active_support/core_ext/string/exclude.rb +++ b/activesupport/lib/active_support/core_ext/string/exclude.rb @@ -1,5 +1,10 @@ class String - # The inverse of String#include?. Returns true if the string does not include the other string. + # The inverse of String#include?. Returns true if the string + # does not include the other string. + # + # "hello".exclude? "lo" #=> false + # "hello".exclude? "ol" #=> true + # "hello".exclude? ?h #=> false def exclude?(string) !include?(string) end -- cgit v1.2.3 From 53cc85fad3440d5817ecf7e0e8cd0c7ff3d9a062 Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Fri, 11 May 2012 17:08:31 -0500 Subject: added docs to String#to_date --- activesupport/lib/active_support/core_ext/string/conversions.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/activesupport/lib/active_support/core_ext/string/conversions.rb b/activesupport/lib/active_support/core_ext/string/conversions.rb index 9084bbee32..c42163a2f0 100644 --- a/activesupport/lib/active_support/core_ext/string/conversions.rb +++ b/activesupport/lib/active_support/core_ext/string/conversions.rb @@ -15,6 +15,12 @@ class String end end + # Converts a string to a Date value. + # + # "1-1-2012".to_date #=> Sun, 01 Jan 2012 + # "01/01/2012".to_date #=> Sun, 01 Jan 2012 + # "2012-12-13".to_date #=> Thu, 13 Dec 2012 + # "12/13/2012".to_date #=> ArgumentError: invalid date def to_date unless blank? date_values = ::Date._parse(self, false).values_at(:year, :mon, :mday) -- cgit v1.2.3 From a0b46b5f1b8b554f438dd4efcbd71274c34a5dae Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Fri, 11 May 2012 17:30:46 -0500 Subject: added docs to String#to_datetime --- activesupport/lib/active_support/core_ext/string/conversions.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/activesupport/lib/active_support/core_ext/string/conversions.rb b/activesupport/lib/active_support/core_ext/string/conversions.rb index c42163a2f0..050eea33ee 100644 --- a/activesupport/lib/active_support/core_ext/string/conversions.rb +++ b/activesupport/lib/active_support/core_ext/string/conversions.rb @@ -29,6 +29,12 @@ class String end end + # Converts a string to a DateTime value. + # + # "1-1-2012".to_datetime #=> Sun, 01 Jan 2012 00:00:00 +0000 + # "01/01/2012 23:59:59".to_datetime #=> Sun, 01 Jan 2012 23:59:59 +0000 + # "2012-12-13 12:50".to_datetime #=> Thu, 13 Dec 2012 12:50:00 +0000 + # "12/13/2012".to_datetime #=> ArgumentError: invalid date def to_datetime unless blank? date_values = ::Date._parse(self, false). -- cgit v1.2.3 From 7dba51288fa2926e65afcc1022491a0f4e3c4d5c Mon Sep 17 00:00:00 2001 From: Erich Menge Date: Fri, 11 May 2012 18:51:01 -0500 Subject: Better document the difference between #clone and #dup. Add #nodoc to initialize_dup and use :method: to document the #dup method. Relates to issue #6235 --- activerecord/lib/active_record/core.rb | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb index a869ed8c04..f376cd034a 100644 --- a/activerecord/lib/active_record/core.rb +++ b/activerecord/lib/active_record/core.rb @@ -204,13 +204,38 @@ module ActiveRecord self end - + + ## + # :method: clone + # Identical to Ruby's clone method. This is a "shallow" copy. Be warned that your attributes are not copied. + # That means that modifying attributes of the clone will modify the original, since they will both point to the + # same attributes hash. If you need a copy of your attributes hash, please use the #dup method. + # + # Example: + # + # user = User.first + # new_user = user.clone + # user.name # => "Bob" + # new_user.name = "Joe" + # user.name # => "Joe" + # + # user.object_id == new_user.object_id # => false + # user.name.object_id == new_user.name.object_id # => true + # + # Use #dup instead, for a copy of the attributes hash. + # user.name.object_id == user.dup.name.object_id # => false + + ## + # :method: dup # Duped objects have no id assigned and are treated as new records. Note # that this is a "shallow" copy as it copies the object's attributes # only, not its associations. The extent of a "deep" copy is application # specific and is therefore left to the application to implement according # to its need. # The dup method does not preserve the timestamps (created|updated)_(at|on). + + ## + # :nodoc: def initialize_dup(other) cloned_attributes = other.clone_attributes(:read_attribute_before_type_cast) self.class.initialize_attributes(cloned_attributes) -- cgit v1.2.3 From fc6ab69777af21db3afb45de8ae08ffc316e69e9 Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Fri, 11 May 2012 23:02:05 -0500 Subject: removing trailing spaces --- activesupport/lib/active_support/core_ext/string/conversions.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/string/conversions.rb b/activesupport/lib/active_support/core_ext/string/conversions.rb index 050eea33ee..022b376aec 100644 --- a/activesupport/lib/active_support/core_ext/string/conversions.rb +++ b/activesupport/lib/active_support/core_ext/string/conversions.rb @@ -17,9 +17,9 @@ class String # Converts a string to a Date value. # - # "1-1-2012".to_date #=> Sun, 01 Jan 2012 - # "01/01/2012".to_date #=> Sun, 01 Jan 2012 - # "2012-12-13".to_date #=> Thu, 13 Dec 2012 + # "1-1-2012".to_date #=> Sun, 01 Jan 2012 + # "01/01/2012".to_date #=> Sun, 01 Jan 2012 + # "2012-12-13".to_date #=> Thu, 13 Dec 2012 # "12/13/2012".to_date #=> ArgumentError: invalid date def to_date unless blank? -- cgit v1.2.3 From c78c29556e3fe338e4f8d27a917765a4f75c9b0d Mon Sep 17 00:00:00 2001 From: Francesco Rodriguez Date: Fri, 11 May 2012 23:16:44 -0500 Subject: added examples to Integer#multiple_of? --- activesupport/lib/active_support/core_ext/integer/multiple.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/activesupport/lib/active_support/core_ext/integer/multiple.rb b/activesupport/lib/active_support/core_ext/integer/multiple.rb index 8dff217ddc..907a0df723 100644 --- a/activesupport/lib/active_support/core_ext/integer/multiple.rb +++ b/activesupport/lib/active_support/core_ext/integer/multiple.rb @@ -1,5 +1,9 @@ class Integer # Check whether the integer is evenly divisible by the argument. + # + # 0.multiple_of?(0) #=> true + # 5.multiple_of?(5) #=> false + # 10.multiple_of?(2) #=> true def multiple_of?(number) number != 0 ? self % number == 0 : zero? end -- cgit v1.2.3 From 219342b642bb3e965147364fabe6a02a8edea559 Mon Sep 17 00:00:00 2001 From: Vasiliy Ermolovich Date: Sat, 12 May 2012 13:31:30 +0300 Subject: remove docs related to ruby 1.8 from Array#wrap --- activesupport/lib/active_support/core_ext/array/wrap.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/array/wrap.rb b/activesupport/lib/active_support/core_ext/array/wrap.rb index 4834eca8b1..9ea93d7226 100644 --- a/activesupport/lib/active_support/core_ext/array/wrap.rb +++ b/activesupport/lib/active_support/core_ext/array/wrap.rb @@ -25,9 +25,6 @@ class Array # Array(:foo => :bar) # => [[:foo, :bar]] # Array.wrap(:foo => :bar) # => [{:foo => :bar}] # - # Array("foo\nbar") # => ["foo\n", "bar"], in Ruby 1.8 - # Array.wrap("foo\nbar") # => ["foo\nbar"] - # # There's also a related idiom that uses the splat operator: # # [*object] -- cgit v1.2.3 From d897255f8a25c72aa72f14d2f82cb87058447fac Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 12 May 2012 18:07:10 +0530 Subject: copy editing [ci skip] --- guides/source/engines.textile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/guides/source/engines.textile b/guides/source/engines.textile index b94ede44c4..880be57fb5 100644 --- a/guides/source/engines.textile +++ b/guides/source/engines.textile @@ -548,16 +548,16 @@ Now instead of the ugly Ruby object output the author's name will be displayed. h5. Using a controller provided by the application -Because Rails controllers generally share code for for things like authentication and accessing session variables, by default they inherit from ApplicationController. Rails engines, however are scoped to run independently from the main application, so each engine gets a scoped ApplicationController. This namespace prevents code collisions, but often engine controllers should access methods in the main application's ApplicationController. An easy way to provide this acess is to change the engine's scoped ApplicationController to inherit from the main application's ApplicationController. For our Blorgh engine this would be done by changing +app/controllers/blorgh/application_controller.rb+ to look like: +Because Rails controllers generally share code for things like authentication and accessing session variables, by default they inherit from ApplicationController. Rails engines, however are scoped to run independently from the main application, so each engine gets a scoped +ApplicationController+. This namespace prevents code collisions, but often engine controllers should access methods in the main application's +ApplicationController+. An easy way to provide this access is to change the engine's scoped +ApplicationController+ to inherit from the main application's +ApplicationController+. For our Blorgh engine this would be done by changing +app/controllers/blorgh/application_controller.rb+ to look like: - class Blorgh::ApplicationController < ApplicationController - end +class Blorgh::ApplicationController < ApplicationController +end -By default, the engine's controllers inherit from Blorgh::ApplicationController. So, after making this change they will have access to the main applications ApplicationController as though they were part of the main application. +By default, the engine's controllers inherit from Blorgh::ApplicationController. So, after making this change they will have access to the main applications +ApplicationController+ as though they were part of the main application. -This change does require that the engine is run from a Rails application that has an ApplicationController. +This change does require that the engine is run from a Rails application that has an +ApplicationController+. h4. Configuring an engine -- cgit v1.2.3 From f2af26dc817281b39a11d1f7131824dfbd4f7a76 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 12 May 2012 18:07:26 +0530 Subject: fix incorrect example [ci skip] --- activesupport/lib/active_support/core_ext/integer/multiple.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/activesupport/lib/active_support/core_ext/integer/multiple.rb b/activesupport/lib/active_support/core_ext/integer/multiple.rb index 907a0df723..7c6c2f1ca7 100644 --- a/activesupport/lib/active_support/core_ext/integer/multiple.rb +++ b/activesupport/lib/active_support/core_ext/integer/multiple.rb @@ -2,7 +2,7 @@ class Integer # Check whether the integer is evenly divisible by the argument. # # 0.multiple_of?(0) #=> true - # 5.multiple_of?(5) #=> false + # 6.multiple_of?(5) #=> false # 10.multiple_of?(2) #=> true def multiple_of?(number) number != 0 ? self % number == 0 : zero? -- cgit v1.2.3 From 84d198b4a0846ae74ff49001adaa7c3c80bc0607 Mon Sep 17 00:00:00 2001 From: Vijay Dev Date: Sat, 12 May 2012 18:10:08 +0530 Subject: copy edits [ci skip] --- activerecord/lib/active_record/core.rb | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/activerecord/lib/active_record/core.rb b/activerecord/lib/active_record/core.rb index f376cd034a..2bf9cb304e 100644 --- a/activerecord/lib/active_record/core.rb +++ b/activerecord/lib/active_record/core.rb @@ -209,9 +209,7 @@ module ActiveRecord # :method: clone # Identical to Ruby's clone method. This is a "shallow" copy. Be warned that your attributes are not copied. # That means that modifying attributes of the clone will modify the original, since they will both point to the - # same attributes hash. If you need a copy of your attributes hash, please use the #dup method. - # - # Example: + # same attributes hash. If you need a copy of your attributes hash, please use the #dup method. # # user = User.first # new_user = user.clone @@ -222,7 +220,6 @@ module ActiveRecord # user.object_id == new_user.object_id # => false # user.name.object_id == new_user.name.object_id # => true # - # Use #dup instead, for a copy of the attributes hash. # user.name.object_id == user.dup.name.object_id # => false ## -- cgit v1.2.3