diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2013-12-08 14:04:04 -0800 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2013-12-08 14:04:04 -0800 |
commit | 4aae538d9ffff3a00a81f3da52fa70f7fd79ac74 (patch) | |
tree | beeb1ef8bab37b48588b0b834229f42d6915e620 /actionpack/lib | |
parent | 186161148a189839a1e0924043f068a8d155ce69 (diff) | |
download | rails-4aae538d9ffff3a00a81f3da52fa70f7fd79ac74.tar.gz rails-4aae538d9ffff3a00a81f3da52fa70f7fd79ac74.tar.bz2 rails-4aae538d9ffff3a00a81f3da52fa70f7fd79ac74.zip |
Revert "Merge pull request #13235 from strzalek/variants-inline" -- needs a little more work!
This reverts commit 186161148a189839a1e0924043f068a8d155ce69, reversing
changes made to cad9eb178ea5eec0e27d74e93518f4ed34e2f997.
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_controller/metal/mime_responds.rb | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/actionpack/lib/action_controller/metal/mime_responds.rb b/actionpack/lib/action_controller/metal/mime_responds.rb index e762ea60a5..b47abb8b8c 100644 --- a/actionpack/lib/action_controller/metal/mime_responds.rb +++ b/actionpack/lib/action_controller/metal/mime_responds.rb @@ -215,7 +215,7 @@ module ActionController #:nodoc: raise ArgumentError, "respond_to takes either types or a block, never both" if mimes.any? && block_given? if collector = retrieve_collector_from_mimes(mimes, &block) - response = collector.response + response = collector.response(request.variant) response ? response.call : render({}) end end @@ -357,7 +357,7 @@ module ActionController #:nodoc: if collector = retrieve_collector_from_mimes(&block) options = resources.size == 1 ? {} : resources.extract_options! options = options.clone - options[:default_response] = collector.response + options[:default_response] = collector.response(request.variant) (options.delete(:responder) || self.class.responder).call(self, resources, options) end end @@ -390,7 +390,7 @@ module ActionController #:nodoc: # is available. def retrieve_collector_from_mimes(mimes=nil, &block) #:nodoc: mimes ||= collect_mimes_from_class_level - collector = Collector.new(mimes, request.variant) + collector = Collector.new(mimes) block.call(collector) if block_given? format = collector.negotiate_format(request) @@ -428,11 +428,9 @@ module ActionController #:nodoc: include AbstractController::Collector attr_accessor :format - def initialize(mimes, variant = nil) + def initialize(mimes) @responses = {} - @variant = variant - - mimes.each { |mime| @responses["Mime::#{mime.upcase}".constantize] = nil } + mimes.each { |mime| send(mime) } end def any(*args, &block) @@ -446,19 +444,15 @@ module ActionController #:nodoc: def custom(mime_type, &block) mime_type = Mime::Type.lookup(mime_type.to_s) unless mime_type.is_a?(Mime::Type) - @responses[mime_type] ||= if block_given? - block - else - VariantFilter.new(@variant) - end + @responses[mime_type] ||= block end - def response + def response(variant) response = @responses.fetch(format, @responses[Mime::ALL]) - if response.is_a?(VariantFilter) || response.nil? || response.arity == 0 + if response.nil? || response.arity == 0 response else - lambda { response.call VariantFilter.new(@variant) } + lambda { response.call VariantFilter.new(variant) } end end |