From edd68a587f412ccdf15613c663acbab341d45017 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 24 Jul 2007 16:48:57 +0000 Subject: Refactored in use of extract_options! (closes #9079) [josh] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7220 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/caching.rb | 4 ++-- actionpack/lib/action_controller/filters.rb | 2 +- actionpack/lib/action_controller/resources.rb | 4 ++-- actionpack/lib/action_view/helpers/active_record_helper.rb | 2 +- actionpack/lib/action_view/helpers/asset_tag_helper.rb | 4 ++-- actionpack/lib/action_view/helpers/form_helper.rb | 4 ++-- actionpack/lib/action_view/helpers/javascript_helper.rb | 4 ++-- actionpack/lib/action_view/helpers/prototype_helper.rb | 2 +- 8 files changed, 13 insertions(+), 13 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_controller/caching.rb b/actionpack/lib/action_controller/caching.rb index 75aa9df812..1b35cbe403 100644 --- a/actionpack/lib/action_controller/caching.rb +++ b/actionpack/lib/action_controller/caching.rb @@ -222,7 +222,7 @@ module ActionController #:nodoc: class ActionCacheFilter #:nodoc: def initialize(*actions, &block) - @options = actions.last.is_a?(Hash) ? actions.pop : {} + @options = actions.extract_options! @actions = Set.new actions end @@ -596,7 +596,7 @@ module ActionController #:nodoc: module ClassMethods #:nodoc: def cache_sweeper(*sweepers) return unless perform_caching - configuration = sweepers.last.is_a?(Hash) ? sweepers.pop : {} + configuration = sweepers.extract_options! sweepers.each do |sweeper| ActiveRecord::Base.observers << sweeper if defined?(ActiveRecord) and defined?(ActiveRecord::Base) sweeper_instance = Object.const_get(Inflector.classify(sweeper)).instance diff --git a/actionpack/lib/action_controller/filters.rb b/actionpack/lib/action_controller/filters.rb index c2f2c2a432..ec3f5096e3 100644 --- a/actionpack/lib/action_controller/filters.rb +++ b/actionpack/lib/action_controller/filters.rb @@ -601,7 +601,7 @@ module ActionController #:nodoc: def extract_conditions(*filters, &block) #:nodoc: filters.flatten! - conditions = filters.last.is_a?(Hash) ? filters.pop : {} + conditions = filters.extract_options! filters << block if block_given? return filters, conditions end diff --git a/actionpack/lib/action_controller/resources.rb b/actionpack/lib/action_controller/resources.rb index 1cfb7c11d0..3cb9367fc2 100644 --- a/actionpack/lib/action_controller/resources.rb +++ b/actionpack/lib/action_controller/resources.rb @@ -295,7 +295,7 @@ module ActionController # HTTP POST on new_message_url will raise a RoutingError exception. The default route in # config/routes.rb overrides this and allows invalid HTTP methods for resource routes. def resources(*entities, &block) - options = entities.last.is_a?(Hash) ? entities.pop : { } + options = entities.extract_options! entities.each { |entity| map_resource(entity, options.dup, &block) } end @@ -369,7 +369,7 @@ module ActionController # edit_account edit_account_url, hash_for_edit_account_url, # edit_account_path, hash_for_edit_account_path def resource(*entities, &block) - options = entities.last.is_a?(Hash) ? entities.pop : { } + options = entities.extract_options! entities.each { |entity| map_singleton_resource(entity, options.dup, &block) } end diff --git a/actionpack/lib/action_view/helpers/active_record_helper.rb b/actionpack/lib/action_view/helpers/active_record_helper.rb index 97ddc41c7e..08abdbd8a8 100644 --- a/actionpack/lib/action_view/helpers/active_record_helper.rb +++ b/actionpack/lib/action_view/helpers/active_record_helper.rb @@ -118,7 +118,7 @@ module ActionView # you need is significantly different from the default presentation, it makes plenty of sense to access the object.errors # instance yourself and set it up. View the source of this method to see how easy it is. def error_messages_for(*params) - options = params.last.is_a?(Hash) ? params.pop.symbolize_keys : {} + options = params.extract_options!.symbolize_keys objects = params.collect {|object_name| instance_variable_get("@#{object_name}") }.compact count = objects.inject(0) {|sum, object| sum + object.errors.count } unless count.zero? diff --git a/actionpack/lib/action_view/helpers/asset_tag_helper.rb b/actionpack/lib/action_view/helpers/asset_tag_helper.rb index 6c4eb0931c..46b08fce76 100644 --- a/actionpack/lib/action_view/helpers/asset_tag_helper.rb +++ b/actionpack/lib/action_view/helpers/asset_tag_helper.rb @@ -172,7 +172,7 @@ module ActionView # javascript_include_tag "prototype", "cart", "checkout", :cache => "shop" # when ActionController::Base.perform_caching is false => # def javascript_include_tag(*sources) - options = sources.last.is_a?(Hash) ? sources.pop.stringify_keys : { } + options = sources.extract_options!.stringify_keys cache = options.delete("cache") if ActionController::Base.perform_caching && cache @@ -281,7 +281,7 @@ module ActionView # stylesheet_link_tag "shop", "cart", "checkout", :cache => "payment" # when ActionController::Base.perform_caching is true => # def stylesheet_link_tag(*sources) - options = sources.last.is_a?(Hash) ? sources.pop.stringify_keys : { } + options = sources.extract_options!.stringify_keys cache = options.delete("cache") if ActionController::Base.perform_caching && cache diff --git a/actionpack/lib/action_view/helpers/form_helper.rb b/actionpack/lib/action_view/helpers/form_helper.rb index 22d2984adb..9c31fb6c90 100644 --- a/actionpack/lib/action_view/helpers/form_helper.rb +++ b/actionpack/lib/action_view/helpers/form_helper.rb @@ -158,7 +158,7 @@ module ActionView def form_for(record_or_name_or_array, *args, &proc) raise ArgumentError, "Missing block" unless block_given? - options = args.last.is_a?(Hash) ? args.pop : {} + options = args.extract_options! case record_or_name_or_array when String, Symbol @@ -212,7 +212,7 @@ module ActionView # like FormOptionHelper#collection_select and DateHelper#datetime_select. def fields_for(object_name, *args, &block) raise ArgumentError, "Missing block" unless block_given? - options = args.last.is_a?(Hash) ? args.pop : {} + options = args.extract_options! object = args.first builder = options[:builder] || ActionView::Base.default_form_builder diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb index 4dd7854367..51cbfb95d9 100644 --- a/actionpack/lib/action_view/helpers/javascript_helper.rb +++ b/actionpack/lib/action_view/helpers/javascript_helper.rb @@ -80,7 +80,7 @@ module ActionView # return false;">Show me more # def link_to_function(name, *args, &block) - html_options = args.last.is_a?(Hash) ? args.pop : {} + html_options = args.extract_options! function = args[0] || '' html_options.symbolize_keys! @@ -111,7 +111,7 @@ module ActionView # page[:details].visual_effect :toggle_slide # end def button_to_function(name, *args, &block) - html_options = args.last.is_a?(Hash) ? args.pop : {} + html_options = args.extract_options! function = args[0] || '' html_options.symbolize_keys! diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb index d1f992486f..0da5cc5579 100644 --- a/actionpack/lib/action_view/helpers/prototype_helper.rb +++ b/actionpack/lib/action_view/helpers/prototype_helper.rb @@ -182,7 +182,7 @@ module ActionView # Works like form_remote_tag, but uses form_for semantics. def remote_form_for(record_or_name, *args, &proc) - options = args.last.is_a?(Hash) ? args.pop : {} + options = args.extract_options! case record_or_name when String, Symbol -- cgit v1.2.3