mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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
This commit is contained in:
parent
34b0811125
commit
edd68a587f
18 changed files with 24 additions and 32 deletions
|
@ -222,7 +222,7 @@ module ActionController #:nodoc:
|
||||||
|
|
||||||
class ActionCacheFilter #:nodoc:
|
class ActionCacheFilter #:nodoc:
|
||||||
def initialize(*actions, &block)
|
def initialize(*actions, &block)
|
||||||
@options = actions.last.is_a?(Hash) ? actions.pop : {}
|
@options = actions.extract_options!
|
||||||
@actions = Set.new actions
|
@actions = Set.new actions
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -596,7 +596,7 @@ module ActionController #:nodoc:
|
||||||
module ClassMethods #:nodoc:
|
module ClassMethods #:nodoc:
|
||||||
def cache_sweeper(*sweepers)
|
def cache_sweeper(*sweepers)
|
||||||
return unless perform_caching
|
return unless perform_caching
|
||||||
configuration = sweepers.last.is_a?(Hash) ? sweepers.pop : {}
|
configuration = sweepers.extract_options!
|
||||||
sweepers.each do |sweeper|
|
sweepers.each do |sweeper|
|
||||||
ActiveRecord::Base.observers << sweeper if defined?(ActiveRecord) and defined?(ActiveRecord::Base)
|
ActiveRecord::Base.observers << sweeper if defined?(ActiveRecord) and defined?(ActiveRecord::Base)
|
||||||
sweeper_instance = Object.const_get(Inflector.classify(sweeper)).instance
|
sweeper_instance = Object.const_get(Inflector.classify(sweeper)).instance
|
||||||
|
|
|
@ -601,7 +601,7 @@ module ActionController #:nodoc:
|
||||||
|
|
||||||
def extract_conditions(*filters, &block) #:nodoc:
|
def extract_conditions(*filters, &block) #:nodoc:
|
||||||
filters.flatten!
|
filters.flatten!
|
||||||
conditions = filters.last.is_a?(Hash) ? filters.pop : {}
|
conditions = filters.extract_options!
|
||||||
filters << block if block_given?
|
filters << block if block_given?
|
||||||
return filters, conditions
|
return filters, conditions
|
||||||
end
|
end
|
||||||
|
|
|
@ -295,7 +295,7 @@ module ActionController
|
||||||
# HTTP POST on <tt>new_message_url</tt> will raise a RoutingError exception. The default route in
|
# HTTP POST on <tt>new_message_url</tt> will raise a RoutingError exception. The default route in
|
||||||
# <tt>config/routes.rb</tt> overrides this and allows invalid HTTP methods for resource routes.
|
# <tt>config/routes.rb</tt> overrides this and allows invalid HTTP methods for resource routes.
|
||||||
def resources(*entities, &block)
|
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) }
|
entities.each { |entity| map_resource(entity, options.dup, &block) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -369,7 +369,7 @@ module ActionController
|
||||||
# edit_account edit_account_url, hash_for_edit_account_url,
|
# edit_account edit_account_url, hash_for_edit_account_url,
|
||||||
# edit_account_path, hash_for_edit_account_path
|
# edit_account_path, hash_for_edit_account_path
|
||||||
def resource(*entities, &block)
|
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) }
|
entities.each { |entity| map_singleton_resource(entity, options.dup, &block) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -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
|
# 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.
|
# instance yourself and set it up. View the source of this method to see how easy it is.
|
||||||
def error_messages_for(*params)
|
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
|
objects = params.collect {|object_name| instance_variable_get("@#{object_name}") }.compact
|
||||||
count = objects.inject(0) {|sum, object| sum + object.errors.count }
|
count = objects.inject(0) {|sum, object| sum + object.errors.count }
|
||||||
unless count.zero?
|
unless count.zero?
|
||||||
|
|
|
@ -172,7 +172,7 @@ module ActionView
|
||||||
# javascript_include_tag "prototype", "cart", "checkout", :cache => "shop" # when ActionController::Base.perform_caching is false =>
|
# javascript_include_tag "prototype", "cart", "checkout", :cache => "shop" # when ActionController::Base.perform_caching is false =>
|
||||||
# <script type="text/javascript" src="/javascripts/shop.js"></script>
|
# <script type="text/javascript" src="/javascripts/shop.js"></script>
|
||||||
def javascript_include_tag(*sources)
|
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")
|
cache = options.delete("cache")
|
||||||
|
|
||||||
if ActionController::Base.perform_caching && 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 =>
|
# stylesheet_link_tag "shop", "cart", "checkout", :cache => "payment" # when ActionController::Base.perform_caching is true =>
|
||||||
# <link href="/stylesheets/payment.css" media="screen" rel="Stylesheet" type="text/css" />
|
# <link href="/stylesheets/payment.css" media="screen" rel="Stylesheet" type="text/css" />
|
||||||
def stylesheet_link_tag(*sources)
|
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")
|
cache = options.delete("cache")
|
||||||
|
|
||||||
if ActionController::Base.perform_caching && cache
|
if ActionController::Base.perform_caching && cache
|
||||||
|
|
|
@ -158,7 +158,7 @@ module ActionView
|
||||||
def form_for(record_or_name_or_array, *args, &proc)
|
def form_for(record_or_name_or_array, *args, &proc)
|
||||||
raise ArgumentError, "Missing block" unless block_given?
|
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
|
case record_or_name_or_array
|
||||||
when String, Symbol
|
when String, Symbol
|
||||||
|
@ -212,7 +212,7 @@ module ActionView
|
||||||
# like FormOptionHelper#collection_select and DateHelper#datetime_select.
|
# like FormOptionHelper#collection_select and DateHelper#datetime_select.
|
||||||
def fields_for(object_name, *args, &block)
|
def fields_for(object_name, *args, &block)
|
||||||
raise ArgumentError, "Missing block" unless block_given?
|
raise ArgumentError, "Missing block" unless block_given?
|
||||||
options = args.last.is_a?(Hash) ? args.pop : {}
|
options = args.extract_options!
|
||||||
object = args.first
|
object = args.first
|
||||||
|
|
||||||
builder = options[:builder] || ActionView::Base.default_form_builder
|
builder = options[:builder] || ActionView::Base.default_form_builder
|
||||||
|
|
|
@ -80,7 +80,7 @@ module ActionView
|
||||||
# return false;">Show me more</a>
|
# return false;">Show me more</a>
|
||||||
#
|
#
|
||||||
def link_to_function(name, *args, &block)
|
def link_to_function(name, *args, &block)
|
||||||
html_options = args.last.is_a?(Hash) ? args.pop : {}
|
html_options = args.extract_options!
|
||||||
function = args[0] || ''
|
function = args[0] || ''
|
||||||
|
|
||||||
html_options.symbolize_keys!
|
html_options.symbolize_keys!
|
||||||
|
@ -111,7 +111,7 @@ module ActionView
|
||||||
# page[:details].visual_effect :toggle_slide
|
# page[:details].visual_effect :toggle_slide
|
||||||
# end
|
# end
|
||||||
def button_to_function(name, *args, &block)
|
def button_to_function(name, *args, &block)
|
||||||
html_options = args.last.is_a?(Hash) ? args.pop : {}
|
html_options = args.extract_options!
|
||||||
function = args[0] || ''
|
function = args[0] || ''
|
||||||
|
|
||||||
html_options.symbolize_keys!
|
html_options.symbolize_keys!
|
||||||
|
|
|
@ -182,7 +182,7 @@ module ActionView
|
||||||
|
|
||||||
# Works like form_remote_tag, but uses form_for semantics.
|
# Works like form_remote_tag, but uses form_for semantics.
|
||||||
def remote_form_for(record_or_name, *args, &proc)
|
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
|
case record_or_name
|
||||||
when String, Symbol
|
when String, Symbol
|
||||||
|
|
|
@ -98,10 +98,6 @@ module ActiveRecord
|
||||||
@reflection.klass.send(:sanitize_sql, sql)
|
@reflection.klass.send(:sanitize_sql, sql)
|
||||||
end
|
end
|
||||||
|
|
||||||
def extract_options_from_args!(args)
|
|
||||||
@owner.send(:extract_options_from_args!, args)
|
|
||||||
end
|
|
||||||
|
|
||||||
def set_belongs_to_association_for(record)
|
def set_belongs_to_association_for(record)
|
||||||
if @reflection.options[:as]
|
if @reflection.options[:as]
|
||||||
record["#{@reflection.options[:as]}_id"] = @owner.id unless @owner.new_record?
|
record["#{@reflection.options[:as]}_id"] = @owner.id unless @owner.new_record?
|
||||||
|
|
|
@ -29,7 +29,7 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def find(*args)
|
def find(*args)
|
||||||
options = Base.send(:extract_options_from_args!, args)
|
options = args.extract_options!
|
||||||
|
|
||||||
# If using a custom finder_sql, scan the entire collection.
|
# If using a custom finder_sql, scan the entire collection.
|
||||||
if @reflection.options[:finder_sql]
|
if @reflection.options[:finder_sql]
|
||||||
|
|
|
@ -38,7 +38,7 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def find(*args)
|
def find(*args)
|
||||||
options = Base.send(:extract_options_from_args!, args)
|
options = args.extract_options!
|
||||||
|
|
||||||
# If using a custom finder_sql, scan the entire collection.
|
# If using a custom finder_sql, scan the entire collection.
|
||||||
if @reflection.options[:finder_sql]
|
if @reflection.options[:finder_sql]
|
||||||
|
|
|
@ -9,7 +9,7 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def find(*args)
|
def find(*args)
|
||||||
options = Base.send(:extract_options_from_args!, args)
|
options = args.extract_options!
|
||||||
|
|
||||||
conditions = "#{@finder_sql}"
|
conditions = "#{@finder_sql}"
|
||||||
if sanitized_conditions = sanitize_sql(options[:conditions])
|
if sanitized_conditions = sanitize_sql(options[:conditions])
|
||||||
|
|
|
@ -421,7 +421,7 @@ module ActiveRecord #:nodoc:
|
||||||
# person.save!
|
# person.save!
|
||||||
# end
|
# end
|
||||||
def find(*args)
|
def find(*args)
|
||||||
options = extract_options_from_args!(args)
|
options = args.extract_options!
|
||||||
validate_find_options(options)
|
validate_find_options(options)
|
||||||
set_readonly_option!(options)
|
set_readonly_option!(options)
|
||||||
|
|
||||||
|
@ -1604,10 +1604,6 @@ module ActiveRecord #:nodoc:
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def extract_options_from_args!(args) #:nodoc:
|
|
||||||
args.last.is_a?(Hash) ? args.pop : {}
|
|
||||||
end
|
|
||||||
|
|
||||||
VALID_FIND_OPTIONS = [ :conditions, :include, :joins, :limit, :offset,
|
VALID_FIND_OPTIONS = [ :conditions, :include, :joins, :limit, :offset,
|
||||||
:order, :select, :readonly, :group, :from, :lock ]
|
:order, :select, :readonly, :group, :from, :lock ]
|
||||||
|
|
||||||
|
|
|
@ -364,7 +364,7 @@ module ActiveRecord
|
||||||
%w( string text integer float decimal datetime timestamp time date binary boolean ).each do |column_type|
|
%w( string text integer float decimal datetime timestamp time date binary boolean ).each do |column_type|
|
||||||
class_eval <<-EOV
|
class_eval <<-EOV
|
||||||
def #{column_type}(*args)
|
def #{column_type}(*args)
|
||||||
options = args.last.is_a?(Hash) ? args.pop : {}
|
options = args.extract_options!
|
||||||
column_names = args
|
column_names = args
|
||||||
|
|
||||||
column_names.each { |name| column(name, '#{column_type}', options) }
|
column_names.each { |name| column(name, '#{column_type}', options) }
|
||||||
|
|
|
@ -21,7 +21,7 @@ class Class # :nodoc:
|
||||||
end
|
end
|
||||||
|
|
||||||
def cattr_writer(*syms)
|
def cattr_writer(*syms)
|
||||||
options = syms.last.is_a?(Hash) ? syms.pop : {}
|
options = syms.extract_options!
|
||||||
syms.flatten.each do |sym|
|
syms.flatten.each do |sym|
|
||||||
class_eval(<<-EOS, __FILE__, __LINE__)
|
class_eval(<<-EOS, __FILE__, __LINE__)
|
||||||
unless defined? @@#{sym}
|
unless defined? @@#{sym}
|
||||||
|
|
|
@ -23,7 +23,7 @@ class Class # :nodoc:
|
||||||
end
|
end
|
||||||
|
|
||||||
def class_inheritable_writer(*syms)
|
def class_inheritable_writer(*syms)
|
||||||
options = syms.last.is_a?(Hash) ? syms.pop : {}
|
options = syms.extract_options!
|
||||||
syms.each do |sym|
|
syms.each do |sym|
|
||||||
class_eval <<-EOS
|
class_eval <<-EOS
|
||||||
def self.#{sym}=(obj)
|
def self.#{sym}=(obj)
|
||||||
|
@ -40,7 +40,7 @@ class Class # :nodoc:
|
||||||
end
|
end
|
||||||
|
|
||||||
def class_inheritable_array_writer(*syms)
|
def class_inheritable_array_writer(*syms)
|
||||||
options = syms.last.is_a?(Hash) ? syms.pop : {}
|
options = syms.extract_options!
|
||||||
syms.each do |sym|
|
syms.each do |sym|
|
||||||
class_eval <<-EOS
|
class_eval <<-EOS
|
||||||
def self.#{sym}=(obj)
|
def self.#{sym}=(obj)
|
||||||
|
@ -57,7 +57,7 @@ class Class # :nodoc:
|
||||||
end
|
end
|
||||||
|
|
||||||
def class_inheritable_hash_writer(*syms)
|
def class_inheritable_hash_writer(*syms)
|
||||||
options = syms.last.is_a?(Hash) ? syms.pop : {}
|
options = syms.extract_options!
|
||||||
syms.each do |sym|
|
syms.each do |sym|
|
||||||
class_eval <<-EOS
|
class_eval <<-EOS
|
||||||
def self.#{sym}=(obj)
|
def self.#{sym}=(obj)
|
||||||
|
|
|
@ -21,7 +21,7 @@ class Module # :nodoc:
|
||||||
end
|
end
|
||||||
|
|
||||||
def mattr_writer(*syms)
|
def mattr_writer(*syms)
|
||||||
options = syms.last.is_a?(Hash) ? syms.pop : {}
|
options = syms.extract_options!
|
||||||
syms.each do |sym|
|
syms.each do |sym|
|
||||||
class_eval(<<-EOS, __FILE__, __LINE__)
|
class_eval(<<-EOS, __FILE__, __LINE__)
|
||||||
unless defined? @@#{sym}
|
unless defined? @@#{sym}
|
||||||
|
|
|
@ -85,7 +85,7 @@ module ActiveSupport
|
||||||
module ClassMethods #:nodoc:
|
module ClassMethods #:nodoc:
|
||||||
# Declare that a method has been deprecated.
|
# Declare that a method has been deprecated.
|
||||||
def deprecate(*method_names)
|
def deprecate(*method_names)
|
||||||
options = method_names.last.is_a?(Hash) ? method_names.pop : {}
|
options = method_names.extract_options!
|
||||||
method_names = method_names + options.keys
|
method_names = method_names + options.keys
|
||||||
method_names.each do |method_name|
|
method_names.each do |method_name|
|
||||||
alias_method_chain(method_name, :deprecation) do |target, punctuation|
|
alias_method_chain(method_name, :deprecation) do |target, punctuation|
|
||||||
|
|
Loading…
Reference in a new issue