From f8ba48c150fb70ed0bcb8ff74cf2aabc81173082 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 21 Sep 2015 14:10:17 -0700 Subject: introduce an `All` mime type This class gives us the `all?` predicate method that returns true without hitting method missing --- actionpack/lib/action_dispatch/http/mime_type.rb | 6 ++++++ actionpack/lib/action_dispatch/http/mime_types.rb | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/http/mime_type.rb b/actionpack/lib/action_dispatch/http/mime_type.rb index 2d49ad661c..553f19b5bc 100644 --- a/actionpack/lib/action_dispatch/http/mime_type.rb +++ b/actionpack/lib/action_dispatch/http/mime_type.rb @@ -331,6 +331,7 @@ to: @@html_types.include?(to_sym) || @string =~ /html/ end + def all?; false; end private @@ -348,6 +349,11 @@ to: def respond_to_missing?(method, include_private = false) #:nodoc: method.to_s.ends_with? '?' end + + class All < Type + def all?; true; end + def html?; true; end + end end class NullType diff --git a/actionpack/lib/action_dispatch/http/mime_types.rb b/actionpack/lib/action_dispatch/http/mime_types.rb index d349cf2807..0af3e5c0df 100644 --- a/actionpack/lib/action_dispatch/http/mime_types.rb +++ b/actionpack/lib/action_dispatch/http/mime_types.rb @@ -33,4 +33,4 @@ Mime::Type.register "application/pdf", :pdf, [], %w(pdf) Mime::Type.register "application/zip", :zip, [], %w(zip) # Create Mime::ALL but do not add it to the SET. -Mime::Type.add_type :ALL, Mime::Type.new("*/*", :all, []) +Mime::Type.add_type :ALL, Mime::Type::All.new("*/*", :all, []) -- cgit v1.2.3