From 0ee1cb2cd32bfaf47deaf5440dd5b9cf0915ab6a Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 2 Oct 2007 05:32:14 +0000 Subject: Ruby 1.9 compat, consistent load paths git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7719 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/assertions.rb | 4 ++-- actionpack/lib/action_controller/base.rb | 18 ++++++++--------- actionpack/lib/action_controller/caching.rb | 12 +++++------ actionpack/lib/action_controller/cgi_process.rb | 6 +++--- actionpack/lib/action_controller/components.rb | 22 ++++++++++----------- actionpack/lib/action_controller/dispatcher.rb | 13 ++++++++---- actionpack/lib/action_controller/filters.rb | 14 +++++++------ actionpack/lib/action_controller/flash.rb | 5 ++--- actionpack/lib/action_controller/helpers.rb | 18 +++++++++-------- .../lib/action_controller/http_authentication.rb | 6 +++--- actionpack/lib/action_controller/integration.rb | 16 +++++++-------- actionpack/lib/action_controller/layout.rb | 10 ++++++---- actionpack/lib/action_controller/mime_responds.rb | 6 ++++-- actionpack/lib/action_controller/mime_type.rb | 6 +++--- .../lib/action_controller/polymorphic_routes.rb | 16 +++++++-------- actionpack/lib/action_controller/request.rb | 23 ++++++++++++---------- actionpack/lib/action_controller/rescue.rb | 4 ++-- actionpack/lib/action_controller/resources.rb | 14 +++++++------ actionpack/lib/action_controller/routing.rb | 20 ++++++++++--------- .../lib/action_controller/session_management.rb | 9 +++++---- actionpack/lib/action_controller/test_process.rb | 18 ++++++++--------- actionpack/lib/action_controller/verification.rb | 4 ++-- .../lib/action_view/helpers/number_helper.rb | 10 +++++----- actionpack/lib/action_view/helpers/text_helper.rb | 2 +- 24 files changed, 148 insertions(+), 128 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/assertions.rb b/actionpack/lib/action_controller/assertions.rb index 7f72e12050..ee4ad5c5ae 100644 --- a/actionpack/lib/action_controller/assertions.rb +++ b/actionpack/lib/action_controller/assertions.rb @@ -46,7 +46,7 @@ module ActionController #:nodoc: 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 @@ module Test #:nodoc: include ActionController::Assertions end end -end \ No newline at end of file +end diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index 9ac728e96a..74d0a6c09a 100755 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -392,7 +392,7 @@ module ActionController #:nodoc: # More methods can be hidden using hide_actions. 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) @@ -400,12 +400,12 @@ module ActionController #:nodoc: # 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 @@ module ActionController #:nodoc: 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 @@ module ActionController #:nodoc: 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 @@ module ActionController #:nodoc: 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 diff --git a/actionpack/lib/action_controller/caching.rb b/actionpack/lib/action_controller/caching.rb index 3689c335fc..a072080849 100644 --- a/actionpack/lib/action_controller/caching.rb +++ b/actionpack/lib/action_controller/caching.rb @@ -238,7 +238,7 @@ module ActionController #:nodoc: 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 @@ module ActionController #: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 @@ module ActionController #:nodoc: 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 @@ module ActionController #:nodoc: 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 diff --git a/actionpack/lib/action_controller/cgi_process.rb b/actionpack/lib/action_controller/cgi_process.rb index 6e8098e746..f3282922e6 100644 --- a/actionpack/lib/action_controller/cgi_process.rb +++ b/actionpack/lib/action_controller/cgi_process.rb @@ -42,7 +42,7 @@ module ActionController #: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 @@ module ActionController #:nodoc: 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 @@ end_msg 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 diff --git a/actionpack/lib/action_controller/components.rb b/actionpack/lib/action_controller/components.rb index 5ef6e2afba..7f7ecfff78 100644 --- a/actionpack/lib/action_controller/components.rb +++ b/actionpack/lib/action_controller/components.rb @@ -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 @@ module ActionController #:nodoc: end end end -end \ No newline at end of file +end diff --git a/actionpack/lib/action_controller/dispatcher.rb b/actionpack/lib/action_controller/dispatcher.rb index 8c5a73c2f5..65f763ca01 100644 --- a/actionpack/lib/action_controller/dispatcher.rb +++ b/actionpack/lib/action_controller/dispatcher.rb @@ -71,7 +71,7 @@ module ActionController 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 @@ module ActionController 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 @@ module ActionController 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 diff --git a/actionpack/lib/action_controller/filters.rb b/actionpack/lib/action_controller/filters.rb index 03b65074f4..c8ad922346 100644 --- a/actionpack/lib/action_controller/filters.rb +++ b/actionpack/lib/action_controller/filters.rb @@ -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 @@ module ActionController #:nodoc: 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 @@ module ActionController #:nodoc: class SymbolFilter < Filter #:nodoc: def call(controller, &block) - controller.send(@filter, &block) + controller.send!(@filter, &block) end end @@ -656,7 +658,7 @@ module ActionController #: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 @@ module ActionController #:nodoc: end end end -end \ No newline at end of file +end diff --git a/actionpack/lib/action_controller/flash.rb b/actionpack/lib/action_controller/flash.rb index b3e39912ce..692168f230 100644 --- a/actionpack/lib/action_controller/flash.rb +++ b/actionpack/lib/action_controller/flash.rb @@ -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 @@ module ActionController #:nodoc: end end end -end \ No newline at end of file +end diff --git a/actionpack/lib/action_controller/helpers.rb b/actionpack/lib/action_controller/helpers.rb index ccdb54c2a1..0e71832144 100644 --- a/actionpack/lib/action_controller/helpers.rb +++ b/actionpack/lib/action_controller/helpers.rb @@ -68,7 +68,7 @@ module ActionController #:nodoc: # 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 @@ module ActionController #:nodoc: 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 @@ module ActionController #:nodoc: 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 @@ module ActionController #:nodoc: end end end -end \ No newline at end of file +end diff --git a/actionpack/lib/action_controller/http_authentication.rb b/actionpack/lib/action_controller/http_authentication.rb index 4e77103de2..170098dc58 100644 --- a/actionpack/lib/action_controller/http_authentication.rb +++ b/actionpack/lib/action_controller/http_authentication.rb @@ -121,9 +121,9 @@ module ActionController 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 \ No newline at end of file +end diff --git a/actionpack/lib/action_controller/integration.rb b/actionpack/lib/action_controller/integration.rb index 677d25b6c9..c981c56e01 100644 --- a/actionpack/lib/action_controller/integration.rb +++ b/actionpack/lib/action_controller/integration.rb @@ -83,7 +83,7 @@ module ActionController # the helpers are made protected by default--we make them public for # easier access during testing and troubleshooting. - klass.send(:public, *Routing::Routes.named_routes.helpers) + klass.module_eval { public *Routing::Routes.named_routes.helpers } @named_routes_configured = true end end @@ -252,7 +252,7 @@ module ActionController end unless ActionController::Base.respond_to?(:clear_last_instantiation!) - ActionController::Base.send(:include, ControllerCapture) + ActionController::Base.module_eval { include ControllerCapture } end ActionController::Base.clear_last_instantiation! @@ -498,7 +498,7 @@ module ActionController reset! unless @integration_session # reset the html_document variable, but only for new get/post calls @html_document = nil unless %w(cookies assigns).include?(method) - returning @integration_session.send(method, *args) do + returning @integration_session.send!(method, *args) do copy_session_variables! end end @@ -522,11 +522,11 @@ module ActionController self.class.fixture_table_names.each do |table_name| name = table_name.tr(".", "_") next unless respond_to?(name) - extras.send(:define_method, name) { |*args| delegate.send(name, *args) } + extras.send!(:define_method, name) { |*args| delegate.send(name, *args) } end # delegate add_assertion to the test case - extras.send(:define_method, :add_assertion) { test_result.add_assertion } + extras.send!(:define_method, :add_assertion) { test_result.add_assertion } session.extend(extras) session.delegate = self session.test_result = @_result @@ -540,16 +540,16 @@ module ActionController def copy_session_variables! #:nodoc: return unless @integration_session %w(controller response request).each do |var| - instance_variable_set("@#{var}", @integration_session.send(var)) + instance_variable_set("@#{var}", @integration_session.send!(var)) end end # Delegate unhandled messages to the current session instance. def method_missing(sym, *args, &block) reset! unless @integration_session - returning @integration_session.send(sym, *args, &block) do + returning @integration_session.send!(sym, *args, &block) do copy_session_variables! end end end -end \ No newline at end of file +end diff --git a/actionpack/lib/action_controller/layout.rb b/actionpack/lib/action_controller/layout.rb index 27ff16c835..c245fe2326 100644 --- a/actionpack/lib/action_controller/layout.rb +++ b/actionpack/lib/action_controller/layout.rb @@ -194,8 +194,10 @@ module ActionController #:nodoc: private def inherited_with_layout(child) inherited_without_layout(child) - layout_match = child.name.underscore.sub(/_controller$/, '').sub(/^controllers\//, '') - child.layout(layout_match, {}, true) unless child.layout_list.grep(%r{layouts/#{layout_match}(\.[a-z][0-9a-z]*)+$}).empty? + unless child.name.blank? + layout_match = child.name.underscore.sub(/_controller$/, '').sub(/^controllers\//, '') + child.layout(layout_match, {}, true) unless child.layout_list.grep(%r{layouts/#{layout_match}(\.[a-z][0-9a-z]*)+$}).empty? + end end def add_layout_conditions(conditions) @@ -230,7 +232,7 @@ module ActionController #:nodoc: layout = passed_layout || self.class.default_layout(response.template.template_format) active_layout = case layout when String then layout - when Symbol then send(layout) + when Symbol then send!(layout) when Proc then layout.call(self) end @@ -316,7 +318,7 @@ module ActionController #:nodoc: def layout_directory?(layout_name) view_paths.find do |path| next unless template_path = Dir[File.join(path, 'layouts', layout_name) + ".*"].first - self.class.send(:layout_directory_exists_cache)[File.dirname(template_path)] + self.class.send!(:layout_directory_exists_cache)[File.dirname(template_path)] end end end diff --git a/actionpack/lib/action_controller/mime_responds.rb b/actionpack/lib/action_controller/mime_responds.rb index 1390d77849..600877fe4c 100644 --- a/actionpack/lib/action_controller/mime_responds.rb +++ b/actionpack/lib/action_controller/mime_responds.rb @@ -1,7 +1,9 @@ module ActionController #:nodoc: module MimeResponds #:nodoc: def self.included(base) - base.send(:include, ActionController::MimeResponds::InstanceMethods) + base.module_eval do + include ActionController::MimeResponds::InstanceMethods + end end module InstanceMethods @@ -176,4 +178,4 @@ module ActionController #:nodoc: end end end -end \ No newline at end of file +end diff --git a/actionpack/lib/action_controller/mime_type.rb b/actionpack/lib/action_controller/mime_type.rb index 29b7723d76..ef5fee0864 100644 --- a/actionpack/lib/action_controller/mime_type.rb +++ b/actionpack/lib/action_controller/mime_type.rb @@ -59,9 +59,9 @@ module Mime end def register(string, symbol, mime_type_synonyms = [], extension_synonyms = [], skip_lookup = false) - Mime.send :const_set, symbol.to_s.upcase, Type.new(string, symbol, mime_type_synonyms) + Mime.instance_eval { const_set symbol.to_s.upcase, Type.new(string, symbol, mime_type_synonyms) } - SET << Mime.send(:const_get, symbol.to_s.upcase) + SET << Mime.const_get(symbol.to_s.upcase) ([string] + mime_type_synonyms).each { |string| LOOKUP[string] = SET.last } unless skip_lookup ([symbol.to_s] + extension_synonyms).each { |ext| EXTENSION_LOOKUP[ext] = SET.last } @@ -160,4 +160,4 @@ module Mime end end -require 'action_controller/mime_types' \ No newline at end of file +require 'action_controller/mime_types' diff --git a/actionpack/lib/action_controller/polymorphic_routes.rb b/actionpack/lib/action_controller/polymorphic_routes.rb index 2e048dfceb..94aefc9aae 100644 --- a/actionpack/lib/action_controller/polymorphic_routes.rb +++ b/actionpack/lib/action_controller/polymorphic_routes.rb @@ -6,8 +6,8 @@ module ActionController namespace = extract_namespace(record_or_hash_or_array) args = case record_or_hash_or_array - when Hash: [ record_or_hash_or_array ] - when Array: record_or_hash_or_array.dup + when Hash; [ record_or_hash_or_array ] + when Array; record_or_hash_or_array.dup else [ record_or_hash_or_array ] end @@ -24,7 +24,7 @@ module ActionController end named_route = build_named_route_call(record_or_hash_or_array, namespace, inflection, options) - send(named_route, *args) + send!(named_route, *args) end def polymorphic_path(record_or_hash_or_array) @@ -55,10 +55,10 @@ module ActionController def build_named_route_call(records, namespace, inflection, options = {}) records = Array.new([extract_record(records)]) unless records.is_a?(Array) - base_segment = "#{RecordIdentifier.send("#{inflection}_class_name", records.pop)}_" + base_segment = "#{RecordIdentifier.send!("#{inflection}_class_name", records.pop)}_" method_root = records.reverse.inject(base_segment) do |string, name| - segment = "#{RecordIdentifier.send("singular_class_name", name)}_" + segment = "#{RecordIdentifier.send!("singular_class_name", name)}_" segment << string end @@ -67,8 +67,8 @@ module ActionController def extract_record(record_or_hash_or_array) case record_or_hash_or_array - when Array: record_or_hash_or_array.last - when Hash: record_or_hash_or_array[:id] + when Array; record_or_hash_or_array.last + when Hash; record_or_hash_or_array[:id] else record_or_hash_or_array end end @@ -85,4 +85,4 @@ module ActionController end end end -end \ No newline at end of file +end diff --git a/actionpack/lib/action_controller/request.rb b/actionpack/lib/action_controller/request.rb index 602b7602b6..17f22864bd 100755 --- a/actionpack/lib/action_controller/request.rb +++ b/actionpack/lib/action_controller/request.rb @@ -109,7 +109,7 @@ module ActionController # "XMLHttpRequest". (The Prototype Javascript library sends this header with # every Ajax request.) def xml_http_request? - not /XMLHttpRequest/i.match(@env['HTTP_X_REQUESTED_WITH']).nil? + !(@env['HTTP_X_REQUESTED_WITH'] !~ /XMLHttpRequest/i) end alias xhr? :xml_http_request? @@ -120,13 +120,10 @@ module ActionController # delimited list in the case of multiple chained proxies; the first is # the originating IP. # - # Security note: Be aware that since remote_ip will check regular HTTP headers, - # it can be tricked by anyone setting those manually. In other words, people can - # pose as whatever IP address they like to this method. That doesn't matter if - # all your doing is using IP addresses for statistical or geographical information, - # but if you want to, for example, limit access to an administrative area by IP, - # you should instead use Request#remote_addr, which can't be spoofed (but also won't - # survive proxy forwards). + # Security note: do not use if IP spoofing is a concern for your + # application. Since remote_ip checks HTTP headers for addresses forwarded + # by proxies, the client may send any IP. remote_addr can't be spoofed but + # also doesn't work behind a proxy, since it's always the proxy's IP. def remote_ip return @env['HTTP_CLIENT_IP'] if @env.include? 'HTTP_CLIENT_IP' @@ -222,7 +219,13 @@ module ActionController unless (env_qs = @env['QUERY_STRING']).nil? || env_qs.empty? uri << '?' << env_qs end - @env['REQUEST_URI'] = uri + + if uri.nil? + @env.delete('REQUEST_URI') + uri + else + @env['REQUEST_URI'] = uri + end end end @@ -682,4 +685,4 @@ module ActionController raise TypeError, "Conflicting types for parameter containers. Expected an instance of #{klass} but found an instance of #{value.class}. This can be caused by colliding Array and Hash parameters like qs[]=value&qs[key]=value." end end -end \ No newline at end of file +end diff --git a/actionpack/lib/action_controller/rescue.rb b/actionpack/lib/action_controller/rescue.rb index 5556c1d15a..4dbb3aca85 100644 --- a/actionpack/lib/action_controller/rescue.rb +++ b/actionpack/lib/action_controller/rescue.rb @@ -150,7 +150,7 @@ module ActionController #:nodoc: add_variables_to_assigns @template.instance_variable_set("@exception", exception) @template.instance_variable_set("@rescues_path", File.dirname(rescues_path("stub"))) - @template.send(:assign_variables_from_controller) + @template.send!(:assign_variables_from_controller) @template.instance_variable_set("@contents", @template.render_file(template_path_for_local_rescue(exception), false)) @@ -207,4 +207,4 @@ module ActionController #:nodoc: end end end -end \ No newline at end of file +end diff --git a/actionpack/lib/action_controller/resources.rb b/actionpack/lib/action_controller/resources.rb index 679945c11f..6c1459cd9f 100644 --- a/actionpack/lib/action_controller/resources.rb +++ b/actionpack/lib/action_controller/resources.rb @@ -513,15 +513,17 @@ module ActionController default_options = { :action => action.to_s } require_id = !resource.kind_of?(SingletonResource) case default_options[:action] - when "index", "new" : default_options.merge(add_conditions_for(resource.conditions, method || :get)).merge(resource.requirements) - when "create" : default_options.merge(add_conditions_for(resource.conditions, method || :post)).merge(resource.requirements) - when "show", "edit" : default_options.merge(add_conditions_for(resource.conditions, method || :get)).merge(resource.requirements(require_id)) - when "update" : default_options.merge(add_conditions_for(resource.conditions, method || :put)).merge(resource.requirements(require_id)) - when "destroy" : default_options.merge(add_conditions_for(resource.conditions, method || :delete)).merge(resource.requirements(require_id)) + when "index", "new"; default_options.merge(add_conditions_for(resource.conditions, method || :get)).merge(resource.requirements) + when "create"; default_options.merge(add_conditions_for(resource.conditions, method || :post)).merge(resource.requirements) + when "show", "edit"; default_options.merge(add_conditions_for(resource.conditions, method || :get)).merge(resource.requirements(require_id)) + when "update"; default_options.merge(add_conditions_for(resource.conditions, method || :put)).merge(resource.requirements(require_id)) + when "destroy"; default_options.merge(add_conditions_for(resource.conditions, method || :delete)).merge(resource.requirements(require_id)) else default_options.merge(add_conditions_for(resource.conditions, method)).merge(resource.requirements) end end end end -ActionController::Routing::RouteSet::Mapper.send :include, ActionController::Resources \ No newline at end of file +class ActionController::Routing::RouteSet::Mapper + include ActionController::Resources +end diff --git a/actionpack/lib/action_controller/routing.rb b/actionpack/lib/action_controller/routing.rb index 8cb2706543..01615e57e7 100644 --- a/actionpack/lib/action_controller/routing.rb +++ b/actionpack/lib/action_controller/routing.rb @@ -1092,7 +1092,7 @@ module ActionController @module ||= Module.new @module.instance_methods.each do |selector| - @module.send :remove_method, selector + @module.class_eval { remove_method selector } end end @@ -1132,7 +1132,9 @@ module ActionController def install(destinations = [ActionController::Base, ActionView::Base], regenerate = false) reset! if regenerate - Array(destinations).each { |dest| dest.send :include, @module } + Array(destinations).each do |dest| + dest.send! :include, @module + end end private @@ -1154,12 +1156,12 @@ module ActionController def define_hash_access(route, name, kind, options) selector = hash_access_name(name, kind) - @module.send :module_eval, <<-end_eval # We use module_eval to avoid leaks + @module.module_eval <<-end_eval # We use module_eval to avoid leaks def #{selector}(options = nil) options ? #{options.inspect}.merge(options) : #{options.inspect} end + protected :#{selector} end_eval - @module.send(:protected, selector) helpers << selector end @@ -1182,7 +1184,7 @@ module ActionController # # foo_url(bar, baz, bang, :sort_by => 'baz') # - @module.send :module_eval, <<-end_eval # We use module_eval to avoid leaks + @module.module_eval <<-end_eval # We use module_eval to avoid leaks def #{selector}(*args) #{generate_optimisation_block(route, kind)} @@ -1199,8 +1201,8 @@ module ActionController url_for(#{hash_access_method}(opts)) end + protected :#{selector} end_eval - @module.send(:protected, selector) helpers << selector end end @@ -1232,7 +1234,7 @@ module ActionController end def install_helpers(destinations = [ActionController::Base, ActionView::Base], regenerate_code = false) - Array(destinations).each { |d| d.send :include, Helpers } + Array(destinations).each { |d| d.module_eval { include Helpers } } named_routes.install(destinations, regenerate_code) end @@ -1362,7 +1364,7 @@ module ActionController if generate_all # Used by caching to expire all paths for a resource return routes.collect do |route| - route.send(method, options, merged, expire_on) + route.send!(method, options, merged, expire_on) end.compact end @@ -1370,7 +1372,7 @@ module ActionController routes = routes_by_controller[controller][action][options.keys.sort_by { |x| x.object_id }] routes.each do |route| - results = route.send(method, options, merged, expire_on) + results = route.send!(method, options, merged, expire_on) return results if results && (!results.is_a?(Array) || results.first) end end diff --git a/actionpack/lib/action_controller/session_management.rb b/actionpack/lib/action_controller/session_management.rb index fdf75b1b94..207db90c83 100644 --- a/actionpack/lib/action_controller/session_management.rb +++ b/actionpack/lib/action_controller/session_management.rb @@ -8,10 +8,11 @@ end module ActionController #:nodoc: module SessionManagement #:nodoc: def self.included(base) - base.extend(ClassMethods) - - base.send :alias_method_chain, :process, :session_management_support - base.send :alias_method_chain, :process_cleanup, :session_management_support + base.class_eval do + extend ClassMethods + alias_method_chain :process, :session_management_support + alias_method_chain :process_cleanup, :session_management_support + end end module ClassMethods diff --git a/actionpack/lib/action_controller/test_process.rb b/actionpack/lib/action_controller/test_process.rb index 9b34f76950..6e4f9d9ac3 100644 --- a/actionpack/lib/action_controller/test_process.rb +++ b/actionpack/lib/action_controller/test_process.rb @@ -357,7 +357,7 @@ module ActionController #:nodoc: alias local_path path def method_missing(method_name, *args, &block) #:nodoc: - @tempfile.send(method_name, *args, &block) + @tempfile.send!(method_name, *args, &block) end end @@ -379,7 +379,7 @@ module ActionController #:nodoc: # Sanity check for required instance variables so we can give an # understandable error message. %w(@controller @request @response).each do |iv_name| - if !instance_variables.include?(iv_name) || instance_variable_get(iv_name).nil? + if !(instance_variables.include?(iv_name) || instance_variables.include?(iv_name.to_sym)) || instance_variable_get(iv_name).nil? raise "#{iv_name} is nil: make sure you set it in your test's setup method." end end @@ -402,7 +402,7 @@ module ActionController #:nodoc: def xml_http_request(request_method, action, parameters = nil, session = nil, flash = nil) @request.env['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest' @request.env['HTTP_ACCEPT'] = 'text/javascript, text/html, application/xml, text/xml, */*' - returning self.send(request_method, action, parameters, session, flash) do + returning send!(request_method, action, parameters, session, flash) do @request.env.delete 'HTTP_X_REQUESTED_WITH' @request.env.delete 'HTTP_ACCEPT' end @@ -444,7 +444,7 @@ module ActionController #:nodoc: def build_request_uri(action, parameters) unless @request.env['REQUEST_URI'] - options = @controller.send(:rewrite_options, parameters) + options = @controller.send!(:rewrite_options, parameters) options.update(:only_path => true, :action => action) url = ActionController::UrlRewriter.new(@request, parameters) @@ -466,7 +466,7 @@ module ActionController #:nodoc: end def method_missing(selector, *args) - return @controller.send(selector, *args) if ActionController::Routing::Routes.named_routes.helpers.include?(selector) + return @controller.send!(selector, *args) if ActionController::Routing::Routes.named_routes.helpers.include?(selector) return super end @@ -502,15 +502,15 @@ module ActionController #:nodoc: # def with_routing real_routes = ActionController::Routing::Routes - ActionController::Routing.send :remove_const, :Routes + ActionController::Routing.module_eval { remove_const :Routes } temporary_routes = ActionController::Routing::RouteSet.new - ActionController::Routing.send :const_set, :Routes, temporary_routes - + ActionController::Routing.module_eval { const_set :Routes, temporary_routes } + yield temporary_routes ensure if ActionController::Routing.const_defined? :Routes - ActionController::Routing.send(:remove_const, :Routes) + ActionController::Routing.module_eval { remove_const :Routes } end ActionController::Routing.const_set(:Routes, real_routes) if real_routes end diff --git a/actionpack/lib/action_controller/verification.rb b/actionpack/lib/action_controller/verification.rb index 131131a1d8..28f12a0133 100644 --- a/actionpack/lib/action_controller/verification.rb +++ b/actionpack/lib/action_controller/verification.rb @@ -72,7 +72,7 @@ module ActionController #:nodoc: def verify(options={}) filter_opts = { :only => options[:only], :except => options[:except] } before_filter(filter_opts) do |c| - c.send :verify_action, options + c.send! :verify_action, options end end end @@ -95,7 +95,7 @@ module ActionController #:nodoc: response.headers.update(options[:add_headers]) if options[:add_headers] unless performed? render(options[:render]) if options[:render] - options[:redirect_to] = self.send(options[:redirect_to]) if options[:redirect_to].is_a? Symbol + options[:redirect_to] = self.send!(options[:redirect_to]) if options[:redirect_to].is_a? Symbol redirect_to(options[:redirect_to]) if options[:redirect_to] end return false diff --git a/actionpack/lib/action_view/helpers/number_helper.rb b/actionpack/lib/action_view/helpers/number_helper.rb index 64e424df2f..0b76f1a48f 100644 --- a/actionpack/lib/action_view/helpers/number_helper.rb +++ b/actionpack/lib/action_view/helpers/number_helper.rb @@ -164,11 +164,11 @@ module ActionView def number_to_human_size(size, precision=1) size = Kernel.Float(size) case - when size.to_i == 1 : "1 Byte" - when size < 1.kilobyte: "%d Bytes" % size - when size < 1.megabyte: "%.#{precision}f KB" % (size / 1.0.kilobyte) - when size < 1.gigabyte: "%.#{precision}f MB" % (size / 1.0.megabyte) - when size < 1.terabyte: "%.#{precision}f GB" % (size / 1.0.gigabyte) + when size.to_i == 1; "1 Byte" + when size < 1.kilobyte; "%d Bytes" % size + when size < 1.megabyte; "%.#{precision}f KB" % (size / 1.0.kilobyte) + when size < 1.gigabyte; "%.#{precision}f MB" % (size / 1.0.megabyte) + when size < 1.terabyte; "%.#{precision}f GB" % (size / 1.0.gigabyte) else "%.#{precision}f TB" % (size / 1.0.terabyte) end.sub(/([0-9])\.?0+ /, '\1 ' ) rescue diff --git a/actionpack/lib/action_view/helpers/text_helper.rb b/actionpack/lib/action_view/helpers/text_helper.rb index e3e17eaf42..adb0e1fa1b 100644 --- a/actionpack/lib/action_view/helpers/text_helper.rb +++ b/actionpack/lib/action_view/helpers/text_helper.rb @@ -580,7 +580,7 @@ module ActionView # Specifies a Set of 'bad' tags that the #sanitize helper will remove completely, as opposed # to just escaping harmless tags like <font> - @@sanitized_bad_tags = Set.new('script') + @@sanitized_bad_tags = Set.new(%w(script)) mattr_reader :sanitized_bad_tags # Specifies the default Set of tags that the #sanitize helper will allow unscathed. -- cgit v1.2.3