Skip to content

Commit

Permalink
Dont log the _method attribute either. Its already available in the h…
Browse files Browse the repository at this point in the history
…eader
  • Loading branch information
dhh committed Nov 4, 2008
2 parents b29f95e + 18bf7b4 commit a909eec
Show file tree
Hide file tree
Showing 37 changed files with 1,167 additions and 47,375 deletions.
17 changes: 4 additions & 13 deletions actionpack/lib/action_controller/base.rb
Expand Up @@ -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.
Expand Down Expand Up @@ -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>.
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion actionpack/lib/action_controller/request.rb
Expand Up @@ -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)
Expand Down
26 changes: 19 additions & 7 deletions actionpack/lib/action_controller/routing/optimisations.rb
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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

Expand Down Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions actionpack/lib/action_view/helpers/text_helper.rb
Expand Up @@ -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.
#
Expand All @@ -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>.
Expand Down
13 changes: 13 additions & 0 deletions actionpack/test/template/url_helper_test.rb
Expand Up @@ -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|
Expand Down
8 changes: 8 additions & 0 deletions activerecord/lib/active_record/associations.rb
Expand Up @@ -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.
#
Expand Down
104 changes: 103 additions & 1 deletion activesupport/lib/active_support/cache.rb
@@ -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)

Expand Down Expand Up @@ -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

Expand All @@ -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)
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions activesupport/lib/active_support/cache/file_store.rb
@@ -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

Expand Down

0 comments on commit a909eec

Please sign in to comment.