Permalink
Browse files

Ruby 1.9 compat, consistent load paths

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7719 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 9264bdc commit 0ee1cb2cd32bfaf47deaf5440dd5b9cf0915ab6a @jeremy jeremy committed Oct 2, 2007
Showing with 304 additions and 275 deletions.
  1. +4 −4 actionmailer/lib/action_mailer/helpers.rb
  2. +2 −2 actionpack/lib/action_controller/assertions.rb
  3. +9 −9 actionpack/lib/action_controller/base.rb
  4. +6 −6 actionpack/lib/action_controller/caching.rb
  5. +3 −3 actionpack/lib/action_controller/cgi_process.rb
  6. +11 −11 actionpack/lib/action_controller/components.rb
  7. +9 −4 actionpack/lib/action_controller/dispatcher.rb
  8. +8 −6 actionpack/lib/action_controller/filters.rb
  9. +2 −3 actionpack/lib/action_controller/flash.rb
  10. +10 −8 actionpack/lib/action_controller/helpers.rb
  11. +3 −3 actionpack/lib/action_controller/http_authentication.rb
  12. +8 −8 actionpack/lib/action_controller/integration.rb
  13. +6 −4 actionpack/lib/action_controller/layout.rb
  14. +4 −2 actionpack/lib/action_controller/mime_responds.rb
  15. +3 −3 actionpack/lib/action_controller/mime_type.rb
  16. +8 −8 actionpack/lib/action_controller/polymorphic_routes.rb
  17. +13 −10 actionpack/lib/action_controller/request.rb
  18. +2 −2 actionpack/lib/action_controller/rescue.rb
  19. +8 −6 actionpack/lib/action_controller/resources.rb
  20. +11 −9 actionpack/lib/action_controller/routing.rb
  21. +5 −4 actionpack/lib/action_controller/session_management.rb
  22. +9 −9 actionpack/lib/action_controller/test_process.rb
  23. +2 −2 actionpack/lib/action_controller/verification.rb
  24. +5 −5 actionpack/lib/action_view/helpers/number_helper.rb
  25. +1 −1 actionpack/lib/action_view/helpers/text_helper.rb
  26. +4 −4 actionpack/test/controller/base_test.rb
  27. +6 −6 actionpack/test/controller/dispatcher_test.rb
  28. +1 −1 actionpack/test/controller/filters_test.rb
  29. +1 −1 actionpack/test/controller/integration_test.rb
  30. +8 −8 actionpack/test/controller/layout_test.rb
  31. +19 −17 actionpack/test/controller/mime_responds_test.rb
  32. +2 −1 actionpack/test/controller/mime_type_test.rb
  33. +3 −3 actionpack/test/controller/render_test.rb
  34. +1 −1 actionpack/test/controller/request_forgery_protection_test.rb
  35. +2 −3 activerecord/test/abstract_unit.rb
  36. +2 −2 activeresource/lib/active_resource/base.rb
  37. +11 −13 activeresource/lib/active_resource/custom_methods.rb
  38. +1 −1 activeresource/lib/active_resource/http_mock.rb
  39. +4 −4 activeresource/test/authorization_test.rb
  40. +3 −3 activeresource/test/base/load_test.rb
  41. +3 −3 activeresource/test/base_errors_test.rb
  42. +8 −5 activeresource/test/base_test.rb
  43. +2 −2 activeresource/test/connection_test.rb
  44. +1 −1 activeresource/test/fixtures/person.rb
  45. +1 −1 activesupport/lib/active_support/clean_logger.rb
  46. +4 −1 activesupport/lib/active_support/core_ext.rb
  47. +4 −4 activesupport/lib/active_support/core_ext/array.rb
  48. +1 −2 activesupport/lib/active_support/core_ext/bigdecimal.rb
  49. +1 −2 activesupport/lib/active_support/core_ext/bigdecimal/{formatting.rb → conversions.rb}
  50. +2 −2 activesupport/lib/active_support/core_ext/cgi.rb
  51. +3 −3 activesupport/lib/active_support/core_ext/class.rb
  52. +3 −3 activesupport/lib/active_support/core_ext/date.rb
  53. +3 −3 activesupport/lib/active_support/core_ext/date_time.rb
  54. +1 −1 activesupport/lib/active_support/core_ext/float.rb
  55. +1 −1 activesupport/lib/active_support/core_ext/hash.rb
  56. +2 −2 activesupport/lib/active_support/core_ext/integer.rb
  57. +5 −5 activesupport/lib/active_support/core_ext/kernel.rb
  58. +8 −8 activesupport/lib/active_support/core_ext/module.rb
  59. +2 −2 activesupport/lib/active_support/core_ext/numeric.rb
  60. +3 −3 activesupport/lib/active_support/core_ext/object.rb
  61. +1 −1 activesupport/lib/active_support/core_ext/pathname.rb
  62. +1 −1 activesupport/lib/active_support/core_ext/range.rb
  63. +6 −6 activesupport/lib/active_support/core_ext/string.rb
  64. +1 −2 activesupport/lib/active_support/core_ext/test.rb
  65. 0 activesupport/lib/active_support/core_ext/test/{difference.rb → unit/assertions.rb}
  66. +3 −3 activesupport/lib/active_support/core_ext/time.rb
  67. +3 −3 activesupport/lib/active_support/dependencies.rb
  68. +3 −3 activesupport/test/core_ext/hash_ext_test.rb
  69. +8 −2 activesupport/test/inflector_test.rb
@@ -49,7 +49,7 @@ def helper(*args, &block)
begin
require_dependency(file_name)
rescue LoadError => load_error
- requiree = / -- (.*?)(\.rb)?$/.match(load_error).to_a[1]
+ requiree = / -- (.*?)(\.rb)?$/.match(load_error.message).to_a[1]
msg = (requiree == file_name) ? "Missing helper file helpers/#{file_name}.rb" : "Can't load file: #{requiree}"
raise LoadError.new(msg).copy_blame!(load_error)
end
@@ -72,7 +72,7 @@ def helper_method(*methods)
methods.flatten.each do |method|
master_helper_module.module_eval <<-end_eval
def #{method}(*args, &block)
- controller.send(%(#{method}), *args, &block)
+ controller.send!(%(#{method}), *args, &block)
end
end_eval
end
@@ -92,7 +92,7 @@ def inherited_with_helper(child)
inherited_without_helper(child)
begin
child.master_helper_module = Module.new
- child.master_helper_module.send :include, master_helper_module
+ child.master_helper_module.send! :include, master_helper_module
child.helper child.name.underscore
rescue MissingSourceFile => e
raise unless e.is_missing?("helpers/#{child.name.underscore}_helper")
@@ -108,4 +108,4 @@ def initialize_template_class_with_helper(assigns)
end
end
end
-end
+end
@@ -46,7 +46,7 @@ module Assertions
def self.included(klass)
%w(response selector tag dom routing model).each do |kind|
require "action_controller/assertions/#{kind}_assertions"
- klass.send :include, const_get("#{kind.camelize}Assertions")
+ klass.module_eval { include const_get("#{kind.camelize}Assertions") }
end
end
@@ -66,4 +66,4 @@ class TestCase #:nodoc:
include ActionController::Assertions
end
end
-end
+end
@@ -392,20 +392,20 @@ def controller_path
# More methods can be hidden using <tt>hide_actions</tt>.
def hidden_actions
unless read_inheritable_attribute(:hidden_actions)
- write_inheritable_attribute(:hidden_actions, ActionController::Base.public_instance_methods)
+ write_inheritable_attribute(:hidden_actions, ActionController::Base.public_instance_methods.map(&:to_s))
end
read_inheritable_attribute(:hidden_actions)
end
# Hide each of the given methods from being callable as actions.
def hide_action(*names)
- write_inheritable_attribute(:hidden_actions, hidden_actions | names.collect { |n| n.to_s })
+ write_inheritable_attribute(:hidden_actions, hidden_actions | names.map(&:to_s))
end
-
+
@@view_paths = {}
-
+
# View load paths determine the bases from which template references can be made. So a call to
# render("test/template") will be looked up in the view load paths array and the closest match will be
# returned.
@@ -844,19 +844,19 @@ def render(options = nil, &block) #:doc:
if collection = options[:collection]
render_for_text(
- @template.send(:render_partial_collection, partial, collection,
+ @template.send!(:render_partial_collection, partial, collection,
options[:spacer_template], options[:locals]), options[:status]
)
else
render_for_text(
- @template.send(:render_partial, partial,
+ @template.send!(:render_partial, partial,
ActionView::Base::ObjectWrapper.new(options[:object]), options[:locals]), options[:status]
)
end
elsif options[:update]
add_variables_to_assigns
- @template.send :evaluate_assigns
+ @template.send! :evaluate_assigns
generator = ActionView::Helpers::PrototypeHelper::JavaScriptGenerator.new(@template, &block)
response.content_type = Mime::JS
@@ -1104,7 +1104,7 @@ def perform_action
send(action_name)
render unless performed?
elsif respond_to? :method_missing
- send(:method_missing, action_name)
+ method_missing action_name
render unless performed?
elsif template_exists? && template_public?
render
@@ -1135,7 +1135,7 @@ def action_methods
end
def self.action_methods
- @action_methods ||= Set.new(public_instance_methods - hidden_actions)
+ @action_methods ||= Set.new(public_instance_methods.map(&:to_s)) - hidden_actions
end
def add_variables_to_assigns
@@ -238,7 +238,7 @@ def before(controller)
if cache = controller.read_fragment(cache_path.path)
controller.rendered_action_cache = true
set_content_type!(controller, cache_path.extension)
- controller.send(:render_for_text, cache)
+ controller.send!(:render_for_text, cache)
false
else
controller.action_cache_path = cache_path
@@ -470,7 +470,7 @@ def initialize #:nodoc:
super
if ActionController::Base.allow_concurrency
@mutex = Mutex.new
- MemoryStore.send(:include, ThreadSafety)
+ MemoryStore.module_eval { include ThreadSafety }
end
end
end
@@ -560,7 +560,7 @@ def initialize(cache_path)
super(cache_path)
if ActionController::Base.allow_concurrency
@mutex = Mutex.new
- FileStore.send(:include, ThreadSafety)
+ FileStore.module_eval { include ThreadSafety }
end
end
end
@@ -642,13 +642,13 @@ def callback(timing)
controller_callback_method_name = "#{timing}_#{controller.controller_name.underscore}"
action_callback_method_name = "#{controller_callback_method_name}_#{controller.action_name}"
- send(controller_callback_method_name) if respond_to?(controller_callback_method_name)
- send(action_callback_method_name) if respond_to?(action_callback_method_name)
+ send!(controller_callback_method_name) if respond_to?(controller_callback_method_name, true)
+ send!(action_callback_method_name) if respond_to?(action_callback_method_name, true)
end
def method_missing(method, *arguments)
return if @controller.nil?
- @controller.send(method, *arguments)
+ @controller.send!(method, *arguments)
end
end
end
@@ -42,7 +42,7 @@ class CgiRequest < AbstractRequest #:nodoc:
def initialize(cgi, session_options = {})
@cgi = cgi
@session_options = session_options
- @env = @cgi.send(:env_table)
+ @env = @cgi.send!(:env_table)
super()
end
@@ -138,7 +138,7 @@ def reset_session
end
def method_missing(method_id, *arguments)
- @cgi.send(method_id, *arguments) rescue super
+ @cgi.send!(method_id, *arguments) rescue super
end
private
@@ -191,7 +191,7 @@ def out(output = $stdout)
begin
output.write(@cgi.header(@headers))
- if @cgi.send(:env_table)['REQUEST_METHOD'] == 'HEAD'
+ if @cgi.send!(:env_table)['REQUEST_METHOD'] == 'HEAD'
return
elsif @body.respond_to?(:call)
# Flush the output now in case the @body Proc uses
@@ -36,20 +36,20 @@ module ActionController #:nodoc:
# So to repeat: Components are a special-purpose approach that can often be replaced with better use of partials and filters.
module Components
def self.included(base) #:nodoc:
- base.send :include, InstanceMethods
- base.extend(ClassMethods)
+ base.class_eval do
+ include InstanceMethods
+ extend ClassMethods
- base.helper do
- def render_component(options)
- @controller.send(:render_component_as_string, options)
+ helper do
+ def render_component(options)
+ @controller.send!(:render_component_as_string, options)
+ end
end
- end
- # If this controller was instantiated to process a component request,
- # +parent_controller+ points to the instantiator of this controller.
- base.send :attr_accessor, :parent_controller
+ # If this controller was instantiated to process a component request,
+ # +parent_controller+ points to the instantiator of this controller.
+ attr_accessor :parent_controller
- base.class_eval do
alias_method_chain :process_cleanup, :components
alias_method_chain :set_session_options, :components
alias_method_chain :flash, :components
@@ -162,4 +162,4 @@ def process_cleanup_with_components
end
end
end
-end
+end
@@ -71,7 +71,7 @@ def failsafe_response_body(status)
end
def log_failsafe_exception(status, exception)
- message = "/!\ FAILSAFE /!\ #{Time.now}\n Status: #{status}\n"
+ message = "/!\\ FAILSAFE /!\\ #{Time.now}\n Status: #{status}\n"
message << " #{exception}\n #{exception.backtrace.join("\n ")}" if exception
failsafe_logger.fatal message
end
@@ -136,7 +136,12 @@ def reload_application
end
def prepare_application(force = false)
- require_dependency 'application' unless defined?(::ApplicationController)
+ begin
+ require_dependency 'application' unless defined?(::ApplicationController)
+ rescue LoadError => error
+ raise unless error.message =~ /application\.rb/
+ end
+
ActiveRecord::Base.verify_active_connections! if defined?(ActiveRecord)
if unprepared || force
@@ -166,10 +171,10 @@ def handle_request
end
def run_callbacks(kind, enumerator = :each)
- callbacks[kind].send(enumerator) do |callback|
+ callbacks[kind].send!(enumerator) do |callback|
case callback
when Proc; callback.call(self)
- when String, Symbol; send(callback)
+ when String, Symbol; send!(callback)
when Array; callback[1].call(self)
else raise ArgumentError, "Unrecognized callback #{callback.inspect}"
end
@@ -1,8 +1,10 @@
module ActionController #:nodoc:
module Filters #:nodoc:
def self.included(base)
- base.extend(ClassMethods)
- base.send(:include, ActionController::Filters::InstanceMethods)
+ base.class_eval do
+ extend ClassMethods
+ include ActionController::Filters::InstanceMethods
+ end
end
# Filters enable controllers to run shared pre and post processing code for its actions. These filters can be used to do
@@ -440,7 +442,7 @@ def type
def run(controller)
# only filters returning false are halted.
if false == @filter.call(controller)
- controller.send :halt_filter_chain, @filter, :returned_false
+ controller.send! :halt_filter_chain, @filter, :returned_false
end
end
@@ -466,7 +468,7 @@ def call(controller)
class SymbolFilter < Filter #:nodoc:
def call(controller, &block)
- controller.send(@filter, &block)
+ controller.send!(@filter, &block)
end
end
@@ -656,7 +658,7 @@ def proxy_before_and_after_filter(filter) #:nodoc:
return filter unless filter_responds_to_before_and_after(filter)
Proc.new do |controller, action|
if filter.before(controller) == false
- controller.send :halt_filter_chain, filter, :returned_false
+ controller.send! :halt_filter_chain, filter, :returned_false
else
begin
action.call
@@ -754,4 +756,4 @@ def halt_filter_chain(filter, reason)
end
end
end
-end
+end
@@ -25,9 +25,8 @@ module ActionController #:nodoc:
# See docs on the FlashHash class for more details about the flash.
module Flash
def self.included(base)
- base.send :include, InstanceMethods
-
base.class_eval do
+ include InstanceMethods
alias_method_chain :assign_shortcuts, :flash
alias_method_chain :process_cleanup, :flash
alias_method_chain :reset_session, :flash
@@ -175,4 +174,4 @@ def process_cleanup_with_flash
end
end
end
-end
+end
@@ -68,7 +68,7 @@ module ClassMethods
# See ActionView::Helpers (link:classes/ActionView/Helpers.html) for more about making your own helper modules
# available to the templates.
def add_template_helper(helper_module) #:nodoc:
- master_helper_module.send(:include, helper_module)
+ master_helper_module.module_eval { include helper_module }
end
# The +helper+ class method can take a series of helper module names, a block, or both.
@@ -169,10 +169,12 @@ def helper_attr(*attrs)
private
def default_helper_module!
- module_name = name.sub(/Controller$|$/, 'Helper')
- module_path = module_name.split('::').map { |m| m.underscore }.join('/')
- require_dependency module_path
- helper module_name.constantize
+ unless name.blank?
+ module_name = name.sub(/Controller$|$/, 'Helper')
+ module_path = module_name.split('::').map { |m| m.underscore }.join('/')
+ require_dependency module_path
+ helper module_name.constantize
+ end
rescue MissingSourceFile => e
raise unless e.is_missing? module_path
logger.debug("#{name}: missing default helper path #{module_path}") if logger
@@ -186,8 +188,8 @@ def inherited_with_helper(child)
begin
child.master_helper_module = Module.new
- child.master_helper_module.send :include, master_helper_module
- child.send :default_helper_module!
+ child.master_helper_module.send! :include, master_helper_module
+ child.send! :default_helper_module!
rescue MissingSourceFile => e
raise unless e.is_missing?("helpers/#{child.controller_path}_helper")
end
@@ -200,4 +202,4 @@ def all_application_helpers
end
end
end
-end
+end
@@ -121,9 +121,9 @@ def encode_credentials(user_name, password)
def authentication_request(controller, realm)
controller.headers["WWW-Authenticate"] = %(Basic realm="#{realm.gsub(/"/, "")}")
- controller.send :render, :text => "HTTP Basic: Access denied.\n", :status => :unauthorized
- return false
+ controller.send! :render, :text => "HTTP Basic: Access denied.\n", :status => :unauthorized
+ return false
end
end
end
-end
+end
Oops, something went wrong.

0 comments on commit 0ee1cb2

Please sign in to comment.