Skip to content

Commit

Permalink
Clean up the config object in ActionPack. Create config_accessor whic…
Browse files Browse the repository at this point in the history
…h just delegates to the config object, reducing the number of deprecations and add specific tests.
  • Loading branch information
josevalim committed Apr 22, 2010
1 parent a8330c2 commit 4163cce
Show file tree
Hide file tree
Showing 18 changed files with 162 additions and 226 deletions.
1 change: 0 additions & 1 deletion actionpack/lib/abstract_controller.rb
Expand Up @@ -12,7 +12,6 @@
module AbstractController
extend ActiveSupport::Autoload

autoload :Assigns
autoload :Base
autoload :Callbacks
autoload :Collector
Expand Down
21 changes: 0 additions & 21 deletions actionpack/lib/abstract_controller/assigns.rb

This file was deleted.

17 changes: 4 additions & 13 deletions actionpack/lib/abstract_controller/base.rb
@@ -1,4 +1,4 @@
require 'active_support/ordered_options'
require 'active_support/configurable'

module AbstractController
class Error < StandardError; end
Expand All @@ -8,6 +8,8 @@ class Base
attr_internal :response_body
attr_internal :action_name

include ActiveSupport::Configurable

class << self
attr_reader :abstract
alias_method :abstract?, :abstract
Expand All @@ -29,14 +31,6 @@ def descendants
@descendants ||= []
end

def config
@config ||= ActiveSupport::InheritableOptions.new(superclass < Base ? superclass.config : {})
end

def configure
yield config
end

# A list of all internal methods for a controller. This finds the first
# abstract superclass of a controller, and gets a list of all public
# instance methods on that abstract class. Public instance methods of
Expand Down Expand Up @@ -99,10 +93,6 @@ def controller_path

abstract!

def config
@config ||= ActiveSupport::InheritableOptions.new(self.class.config)
end

# Calls the action going through the entire action dispatch stack.
#
# The actual method that is called is determined by calling
Expand Down Expand Up @@ -133,6 +123,7 @@ def action_methods
end

private

# Returns true if the name can be considered an action. This can
# be overridden in subclasses to modify the semantics of what
# can be considered an action.
Expand Down
1 change: 0 additions & 1 deletion actionpack/lib/abstract_controller/helpers.rb
Expand Up @@ -8,7 +8,6 @@ module Helpers

included do
class_attribute :_helpers
delegate :_helpers, :to => :'self.class'
self._helpers = Module.new
end

Expand Down
2 changes: 1 addition & 1 deletion actionpack/lib/abstract_controller/logger.rb
Expand Up @@ -6,7 +6,7 @@ module Logger
extend ActiveSupport::Concern

included do
cattr_accessor :logger
config_accessor :logger
extend ActiveSupport::Benchmarkable
end
end
Expand Down
5 changes: 4 additions & 1 deletion actionpack/lib/action_controller/base.rb
Expand Up @@ -65,8 +65,11 @@ def self.subclasses
@subclasses ||= []
end

# TODO Move this to the appropriate module
config_accessor :assets_dir, :asset_path, :javascripts_dir, :stylesheets_dir

ActiveSupport.run_load_hooks(:action_controller, self)
end
end

require "action_controller/deprecated/base"
require "action_controller/deprecated/base"
6 changes: 2 additions & 4 deletions actionpack/lib/action_controller/caching.rb
Expand Up @@ -63,12 +63,10 @@ def cache_configured?
included do
extend ConfigMethods

delegate :perform_caching, :perform_caching=, :to => :config
singleton_class.delegate :perform_caching, :perform_caching=, :to => :config
self.perform_caching = true
config_accessor :perform_caching
self.perform_caching = true if perform_caching.nil?
end


def caching_allowed?
request.get? && response.status == 200
end
Expand Down
8 changes: 4 additions & 4 deletions actionpack/lib/action_controller/caching/pages.rb
Expand Up @@ -44,17 +44,17 @@ module Pages
# For Rails, this directory has already been set to Rails.public_path (which is usually set to <tt>Rails.root + "/public"</tt>). Changing
# this setting can be useful to avoid naming conflicts with files in <tt>public/</tt>, but doing so will likely require configuring your
# web server to look in the new location for cached files.
singleton_class.delegate :page_cache_directory, :page_cache_directory=, :to => :config
self.page_cache_directory = ''
config_accessor :page_cache_directory
self.page_cache_directory ||= ''

##
# :singleton-method:
# Most Rails requests do not have an extension, such as <tt>/weblog/new</tt>. In these cases, the page caching mechanism will add one in
# order to make it easy for the cached files to be picked up properly by the web server. By default, this cache extension is <tt>.html</tt>.
# If you want something else, like <tt>.php</tt> or <tt>.shtml</tt>, just set Base.page_cache_extension. In cases where a request already has an
# extension, such as <tt>.xml</tt> or <tt>.rss</tt>, page caching will not add an extension. This allows it to work well with RESTful apps.
singleton_class.delegate :page_cache_extension, :page_cache_extension=, :to => :config
self.page_cache_extension = '.html'
config_accessor :page_cache_extension
self.page_cache_extension ||= '.html'
end

module ClassMethods
Expand Down
48 changes: 9 additions & 39 deletions actionpack/lib/action_controller/deprecated/base.rb
@@ -1,33 +1,16 @@
module ActionController
class Base
class << self
def deprecated_config_accessor(option, message = nil)
deprecated_config_reader(option, message)
deprecated_config_writer(option, message)
# Deprecated methods. Wrap them in a module so they can be overwritten by plugins
# (like the verify method.)
module DeprecatedBehavior #:nodoc:
def relative_url_root
ActiveSupport::Deprecation.warn "ActionController::Base.relative_url_root is ineffective. " <<
"Please stop using it.", caller
end

def deprecated_config_reader(option, message = nil)
message ||= "Reading #{option} directly from ActionController::Base is deprecated. " \
"Please read it from config.#{option}"

self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{option}
ActiveSupport::Deprecation.warn #{message.inspect}, caller
config.#{option}
end
RUBY
end

def deprecated_config_writer(option, message = nil)
message ||= "Setting #{option} directly on ActionController::Base is deprecated. " \
"Please set it on config.action_controller.#{option}"

self.class_eval <<-RUBY, __FILE__, __LINE__ + 1
def #{option}=(val)
ActiveSupport::Deprecation.warn #{message.inspect}, caller
config.#{option} = val
end
RUBY
def relative_url_root=
ActiveSupport::Deprecation.warn "ActionController::Base.relative_url_root= is ineffective. " <<
"Please stop using it.", caller
end

def consider_all_requests_local
Expand Down Expand Up @@ -125,9 +108,7 @@ def use_accept_header
def use_accept_header=(val)
use_accept_header
end
end

module DeprecatedBehavior
# This method has been moved to ActionDispatch::Request.filter_parameters
def filter_parameter_logging(*args, &block)
ActiveSupport::Deprecation.warn("Setting filter_parameter_logging in ActionController is deprecated and has no longer effect, please set 'config.filter_parameters' in config/application.rb instead", caller)
Expand All @@ -146,17 +127,6 @@ def verify(*args)

extend DeprecatedBehavior

deprecated_config_writer :session_options
deprecated_config_writer :session_store

deprecated_config_accessor :assets_dir
deprecated_config_accessor :asset_path
deprecated_config_accessor :helpers_path
deprecated_config_accessor :javascripts_dir
deprecated_config_accessor :page_cache_directory
deprecated_config_accessor :relative_url_root, "relative_url_root is ineffective. Please stop using it"
deprecated_config_accessor :stylesheets_dir

delegate :consider_all_requests_local, :consider_all_requests_local=,
:allow_concurrency, :allow_concurrency=, :to => :"self.class"
end
Expand Down
4 changes: 2 additions & 2 deletions actionpack/lib/action_controller/metal/compatibility.rb
Expand Up @@ -21,8 +21,8 @@ class << self
delegate :default_charset=, :to => "ActionDispatch::Response"
end

# cattr_reader :protected_instance_variables
cattr_accessor :protected_instance_variables
# TODO: Update protected instance variables list
config_accessor :protected_instance_variables
self.protected_instance_variables = %w(@assigns @performed_redirect @performed_render
@variables_added @request_origin @url
@parent_controller @action_name
Expand Down
4 changes: 2 additions & 2 deletions actionpack/lib/action_controller/metal/helpers.rb
Expand Up @@ -52,8 +52,8 @@ module Helpers
include AbstractController::Helpers

included do
class_attribute :helpers_path
self.helpers_path = []
config_accessor :helpers_path
self.helpers_path ||= []
end

module ClassMethods
Expand Down

0 comments on commit 4163cce

Please sign in to comment.