lib/lotus/action/mime.rb
# Restrict the access to the specified mime type symbols.
#
# @param mime_types[Array<Symbol>] one or more symbols representing mime type(s)
#
# @since 0.1.0
#
# @example
#   require 'lotus/controller'
#
#   class Show
#     include Lotus::Action
#     accept :html, :json
#
#     def call(params)
#       # ...
#     end
#   end
#
#   # When called with "*/*"              => 200
#   # When called with "text/html"        => 200
#   # When called with "application/json" => 200
#   # When called with "application/xml"  => 406
Restrict the access to the specified mime type symbols.
Restrict the access to the specified mime type symbols .
def accept(*mime_types)
          mime_types = mime_types.map do |mt|
            ::Rack::Mime.mime_type ".#{ mt }"
          end
          before do
            unless mime_types.find {|mt| accept?(mt) }
              halt 406
            end
          end
        end
def accept ( * mime_types ) mime_types = mime_types . map do | mt | :: Rack :: Mime . mime_type ".#{ mt }" end before do unless mime_types . find { | mt | accept? ( mt ) } halt 406 end end end
Restrict the access to the specified mime type symbols.
Restrict the access to the specified mime type symbols .
mime_types
one or more symbols representing mime type(s)
one or more symbols representing mime type ( s )
since
None
example
require 'lotus/controller' class Show include Lotus::Action accept :html, :json def call(params) # ... end end # When called with "*" => 200 # When called with "text/html" => 200 # When called with "application/json" => 200 # When called with "application/xml" => 406
require ' lotus / controller ' class Show include Lotus :: Action accept : html : json def call ( params ) # ... end end # When called with " * " = > 200 # When called with " text / html " = > 200 # When called with " application / json " = > 200 # When called with " application / xml " = > 406