Permalink
Browse files

Dont log the _method attribute either. Its already available in the h…

…eader
  • Loading branch information...
dhh committed Nov 4, 2008
2 parents b29f95e + 18bf7b4 commit a909eecbbd42e70a5bc0e099485f07dc64db5d38
Showing with 1,167 additions and 47,375 deletions.
  1. +4 −13 actionpack/lib/action_controller/base.rb
  2. +2 −1 actionpack/lib/action_controller/request.rb
  3. +19 −7 actionpack/lib/action_controller/routing/optimisations.rb
  4. +5 −5 actionpack/lib/action_view/helpers/text_helper.rb
  5. +13 −0 actionpack/test/template/url_helper_test.rb
  6. +8 −0 activerecord/lib/active_record/associations.rb
  7. +103 −1 activesupport/lib/active_support/cache.rb
  8. +1 −0 activesupport/lib/active_support/cache/file_store.rb
  9. +33 −9 activesupport/lib/active_support/cache/mem_cache_store.rb
  10. +14 −0 activesupport/lib/active_support/cache/memory_store.rb
  11. +1 −0 activesupport/lib/active_support/cache/synchronized_memory_store.rb
  12. +1 −1 activesupport/lib/active_support/testing/performance.rb
  13. +44 −24 railties/doc/guides/html/2_2_release_notes.html
  14. +0 −1 railties/doc/guides/html/actioncontroller_basics.html
  15. +9 −1 railties/doc/guides/html/association_basics.html
  16. +343 −310 railties/doc/guides/html/finders.html
  17. +5 −0 railties/doc/guides/html/getting_started_with_rails.html
  18. +0 −16 railties/doc/guides/html/index.html
  19. +110 −48 railties/doc/guides/html/layouts_and_rendering.html
  20. +1 −1 railties/doc/guides/html/routing_outside_in.html
  21. +14 −0 railties/doc/guides/html/security.html
  22. +28 −24 railties/doc/guides/source/2_2_release_notes.txt
  23. +0 −2 railties/doc/guides/source/actioncontroller_basics/filters.txt
  24. +2 −2 railties/doc/guides/source/active_record_basics.txt
  25. +3 −1 railties/doc/guides/source/association_basics.txt
  26. +0 −45,904 railties/doc/guides/source/benchmarking_and_profiling/examples/graph.html
  27. +0 −412 railties/doc/guides/source/benchmarking_and_profiling/images/kgraph.png.html
  28. +0 −412 railties/doc/guides/source/benchmarking_and_profiling/images/klist.png.html
  29. +302 −143 railties/doc/guides/source/finders.txt
  30. +1 −0 railties/doc/guides/source/getting_started_with_rails.txt
  31. +0 −4 railties/doc/guides/source/index.txt
  32. +67 −18 railties/doc/guides/source/layouts_and_rendering.txt
  33. +1 −1 railties/doc/guides/source/routing_outside_in.txt
  34. +6 −0 railties/doc/guides/source/security.txt
  35. +1 −0 railties/lib/initializer.rb
  36. +24 −13 railties/lib/rails/gem_dependency.rb
  37. +2 −1 railties/lib/tasks/gems.rake
@@ -278,12 +278,6 @@ class Base
@@consider_all_requests_local = true
cattr_accessor :consider_all_requests_local
- # Enable or disable the collection of failure information for RoutingErrors.
- # This information can be extremely useful when tweaking custom routes, but is
- # pointless once routes have been tested and verified.
- @@debug_routes = true
- cattr_accessor :debug_routes
-
# Indicates whether to allow concurrent action processing. Your
# controller actions and any other code they call must also behave well
# when called from concurrent threads. Turned off by default.
@@ -364,11 +358,8 @@ class Base
# If you are deploying to a subdirectory, you will need to set
# <tt>config.action_controller.relative_url_root</tt>
# This defaults to ENV['RAILS_RELATIVE_URL_ROOT']
- cattr_writer :relative_url_root
-
- def self.relative_url_root
- @@relative_url_root || ENV['RAILS_RELATIVE_URL_ROOT']
- end
+ cattr_accessor :relative_url_root
+ self.relative_url_root = ENV['RAILS_RELATIVE_URL_ROOT']
# Holds the request object that's primarily used to get environment variables through access like
# <tt>request.env["REQUEST_URI"]</tt>.
@@ -1247,8 +1238,8 @@ def log_processing_for_session_id
end
def log_processing_for_parameters
- parameters = respond_to?(:filter_parameters) ? filter_parameters(params) : params
- parameters = parameters.except(:controller, :action, :format, :_method)
+ parameters = respond_to?(:filter_parameters) ? filter_parameters(params) : params.dup
+ parameters = parameters.except!(:controller, :action, :format, :_method)
logger.info " Parameters: #{parameters.inspect}"
end
@@ -9,10 +9,11 @@ module ActionController
class AbstractRequest
extend ActiveSupport::Memoizable
- def self.relative_url_root=(*args)
+ def self.relative_url_root=(relative_url_root)
ActiveSupport::Deprecation.warn(
"ActionController::AbstractRequest.relative_url_root= has been renamed." +
"You can now set it with config.action_controller.relative_url_root=", caller)
+ ActionController::base.relative_url_root=relative_url_root
end
HTTP_METHODS = %w(get head put post delete options)
@@ -20,14 +20,20 @@ def generate_optimisation_block(route, kind)
class Optimiser
attr_reader :route, :kind
+ GLOBAL_GUARD_CONDITIONS = [
+ "(!defined?(default_url_options) || default_url_options.blank?)",
+ "(!defined?(controller.default_url_options) || controller.default_url_options.blank?)",
+ "defined?(request)",
+ "request"
+ ]
def initialize(route, kind)
@route = route
@kind = kind
end
- def guard_condition
- 'false'
+ def guard_conditions
+ ["false"]
end
def generation_code
@@ -36,6 +42,7 @@ def generation_code
def source_code
if applicable?
+ guard_condition = (GLOBAL_GUARD_CONDITIONS + guard_conditions).join(" && ")
"return #{generation_code} if #{guard_condition}\n"
else
"\n"
@@ -57,14 +64,14 @@ def applicable?
# return a string like "/people/#{@person.to_param}"
# rather than triggering the expensive logic in +url_for+.
class PositionalArguments < Optimiser
- def guard_condition
+ def guard_conditions
number_of_arguments = route.segment_keys.size
# if they're using foo_url(:id=>2) it's one
# argument, but we don't want to generate /foos/id2
if number_of_arguments == 1
- "(!defined?(default_url_options) || default_url_options.blank?) && defined?(request) && request && args.size == 1 && !args.first.is_a?(Hash)"
+ ["args.size == 1", "!args.first.is_a?(Hash)"]
else
- "(!defined?(default_url_options) || default_url_options.blank?) && defined?(request) && request && args.size == #{number_of_arguments}"
+ ["args.size == #{number_of_arguments}"]
end
end
@@ -98,8 +105,13 @@ def generation_code
# above, but it supports additional query parameters as the last
# argument
class PositionalArgumentsWithAdditionalParams < PositionalArguments
- def guard_condition
- "(!defined?(default_url_options) || default_url_options.blank?) && defined?(request) && request && args.size == #{route.segment_keys.size + 1} && !args.last.has_key?(:anchor) && !args.last.has_key?(:port) && !args.last.has_key?(:host)"
+ def guard_conditions
+ [
+ "args.size == #{route.segment_keys.size + 1}",
+ "!args.last.has_key?(:anchor)",
+ "!args.last.has_key?(:port)",
+ "!args.last.has_key?(:host)"
+ ]
end
# This case uses almost the same code as positional arguments,
@@ -344,9 +344,9 @@ def simple_format(text, html_options={})
text << "</p>"
end
- # Turns all URLs and e-mail addresses into clickable links. The +link+ parameter
+ # Turns all URLs and e-mail addresses into clickable links. The <tt>:link</tt> option
# will limit what should be linked. You can add HTML attributes to the links using
- # +href_options+. Options for +link+ are <tt>:all</tt> (default),
+ # <tt>:href_options</tt>. Possible values for <tt>:link</tt> are <tt>:all</tt> (default),
# <tt>:email_addresses</tt>, and <tt>:urls</tt>. If a block is given, each URL and
# e-mail address is yielded and the result is used as the link text.
#
@@ -355,15 +355,15 @@ def simple_format(text, html_options={})
# # => "Go to <a href=\"http://www.rubyonrails.org\">http://www.rubyonrails.org</a> and
# # say hello to <a href=\"mailto:david@loudthinking.com\">david@loudthinking.com</a>"
#
- # auto_link("Visit http://www.loudthinking.com/ or e-mail david@loudthinking.com", :urls)
+ # auto_link("Visit http://www.loudthinking.com/ or e-mail david@loudthinking.com", :link => :urls)
# # => "Visit <a href=\"http://www.loudthinking.com/\">http://www.loudthinking.com/</a>
# # or e-mail david@loudthinking.com"
#
- # auto_link("Visit http://www.loudthinking.com/ or e-mail david@loudthinking.com", :email_addresses)
+ # auto_link("Visit http://www.loudthinking.com/ or e-mail david@loudthinking.com", :link => :email_addresses)
# # => "Visit http://www.loudthinking.com/ or e-mail <a href=\"mailto:david@loudthinking.com\">david@loudthinking.com</a>"
#
# post_body = "Welcome to my new blog at http://www.myblog.com/. Please e-mail me at me@email.com."
- # auto_link(post_body, :all, :target => '_blank') do |text|
+ # auto_link(post_body, :href_options => { :target => '_blank' }) do |text|
# truncate(text, 15)
# end
# # => "Welcome to my new blog at <a href=\"http://www.myblog.com/\" target=\"_blank\">http://www.m...</a>.
@@ -376,6 +376,19 @@ def test_url_for_nil_returns_current_path
assert_equal '/url_helper_with_controller/nil_url_for', @response.body
end
+ def test_named_route_should_show_host_and_path_using_controller_default_url_options
+ class << @controller
+ def default_url_options(options = nil)
+ {:host => 'testtwo.host'}
+ end
+ end
+
+ with_url_helper_routing do
+ get :show_named_route, :kind => 'url'
+ assert_equal 'http://testtwo.host/url_helper_with_controller/show_named_route', @response.body
+ end
+ end
+
protected
def with_url_helper_routing
with_routing do |set|
@@ -507,6 +507,14 @@ def clear_association_cache #:nodoc:
#
# will load posts and eager load the +approved_comments+ association, which contains only those comments that have been approved.
#
+ # If you eager load an association with a specified <tt>:limit</tt> option, it will be ignored, returning all the associated objects:
+ #
+ # class Picture < ActiveRecord::Base
+ # has_many :most_recent_comments, :class_name => 'Comment', :order => 'id DESC', :limit => 10
+ # end
+ #
+ # Picture.find(:first, :include => :most_recent_comments).most_recent_comments # => returns all associated comments.
+ #
# When eager loaded, conditions are interpolated in the context of the model class, not the model instance. Conditions are lazily interpolated
# before the actual model exists.
#
@@ -1,7 +1,33 @@
require 'benchmark'
module ActiveSupport
+ # See ActiveSupport::Cache::Store for documentation.
module Cache
+ # Creates a new CacheStore object according to the given options.
+ #
+ # If no arguments are passed to this method, then a new
+ # ActiveSupport::Cache::MemoryStore object will be returned.
+ #
+ # If you pass a Symbol as the first argument, then a corresponding cache
+ # store class under the ActiveSupport::Cache namespace will be created.
+ # For example:
+ #
+ # ActiveSupport::Cache.lookup_store(:memory_store)
+ # # => returns a new ActiveSupport::Cache::MemoryStore object
+ #
+ # ActiveSupport::Cache.lookup_store(:drb_store)
+ # # => returns a new ActiveSupport::Cache::DRbStore object
+ #
+ # Any additional arguments will be passed to the corresponding cache store
+ # class's constructor:
+ #
+ # ActiveSupport::Cache.lookup_store(:file_store, "/tmp/cache")
+ # # => same as: ActiveSupport::Cache::FileStore.new("/tmp/cache")
+ #
+ # If the first argument is not a Symbol, then it will simply be returned:
+ #
+ # ActiveSupport::Cache.lookup_store(MyOwnCacheStore.new)
+ # # => returns MyOwnCacheStore.new
def self.lookup_store(*store_option)
store, *parameters = *([ store_option ].flatten)
@@ -36,6 +62,21 @@ def self.expand_cache_key(key, namespace = nil)
expanded_cache_key
end
+ # An abstract cache store class. There are multiple cache store
+ # implementations, each having its own additional features. See the classes
+ # under the ActiveSupport::Cache module, e.g.
+ # ActiveSupport::Cache::MemCacheStore. MemCacheStore is currently the most
+ # popular cache store for large production websites.
+ #
+ # ActiveSupport::Cache::Store is meant for caching strings. Some cache
+ # store implementations, like MemoryStore, are able to cache arbitrary
+ # Ruby objects, but don't count on every cache store to be able to do that.
+ #
+ # cache = ActiveSupport::Cache::MemoryStore.new
+ #
+ # cache.read("city") # => nil
+ # cache.write("city", "Duckburgh")
+ # cache.read("city") # => "Duckburgh"
class Store
cattr_accessor :logger
@@ -44,7 +85,46 @@ def silence!
self
end
- # Pass <tt>:force => true</tt> to force a cache miss.
+ # Fetches data from the cache, using the given key. If there is data in
+ # the cache with the given key, then that data is returned.
+ #
+ # If there is no such data in the cache (a cache miss occurred), then
+ # then nil will be returned. However, if a block has been passed, then
+ # that block will be run in the event of a cache miss. The return value
+ # of the block will be written to the cache under the given cache key,
+ # and that return value will be returned.
+ #
+ # cache.write("today", "Monday")
+ # cache.fetch("today") # => "Monday"
+ #
+ # cache.fetch("city") # => nil
+ # cache.fetch("city") do
+ # "Duckburgh"
+ # end
+ # cache.fetch("city") # => "Duckburgh"
+ #
+ # You may also specify additional options via the +options+ argument.
+ # Setting <tt>:force => true</tt> will force a cache miss:
+ #
+ # cache.write("today", "Monday")
+ # cache.fetch("today", :force => true) # => nil
+ #
+ # Other options will be handled by the specific cache store implementation.
+ # Internally, #fetch calls #read, and calls #write on a cache miss.
+ # +options+ will be passed to the #read and #write calls.
+ #
+ # For example, MemCacheStore's #write method supports the +:expires_in+
+ # option, which tells the memcached server to automatically expire the
+ # cache item after a certain period. We can use this option with #fetch
+ # too:
+ #
+ # cache = ActiveSupport::Cache::MemCacheStore.new
+ # cache.fetch("foo", :force => true, :expires_in => 5.seconds) do
+ # "bar"
+ # end
+ # cache.fetch("foo") # => "bar"
+ # sleep(6)
+ # cache.fetch("foo") # => nil
def fetch(key, options = {})
@logger_off = true
if !options[:force] && value = read(key, options)
@@ -68,10 +148,32 @@ def fetch(key, options = {})
end
end
+ # Fetches data from the cache, using the given key. If there is data in
+ # the cache with the given key, then that data is returned. Otherwise,
+ # nil is returned.
+ #
+ # You may also specify additional options via the +options+ argument.
+ # The specific cache store implementation will decide what to do with
+ # +options+.
def read(key, options = nil)
log("read", key, options)
end
+ # Writes the given value to the cache, with the given key.
+ #
+ # You may also specify additional options via the +options+ argument.
+ # The specific cache store implementation will decide what to do with
+ # +options+.
+ #
+ # For example, MemCacheStore supports the +:expires_in+ option, which
+ # tells the memcached server to automatically expire the cache item after
+ # a certain period:
+ #
+ # cache = ActiveSupport::Cache::MemCacheStore.new
+ # cache.write("foo", "bar", :expires_in => 5.seconds)
+ # cache.read("foo") # => "bar"
+ # sleep(6)
+ # cache.read("foo") # => nil
def write(key, value, options = nil)
log("write", key, options)
end
@@ -1,5 +1,6 @@
module ActiveSupport
module Cache
+ # A cache store implementation which stores everything on the filesystem.
class FileStore < Store
attr_reader :cache_path
Oops, something went wrong.

0 comments on commit a909eec

Please sign in to comment.