Module: Lotus::Action::Mime::ClassMethods

Defined in:
lib/lotus/action/mime.rb

Overview

Since:

  • 0.1.0

Instance Method Summary collapse

Instance Method Details

#accept(*mime_types) ⇒ Object (protected)

Restrict the access to the specified mime type symbols.

Examples:

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

Parameters:

  • mime_types (Array<Symbol>)

    one or more symbols representing mime type(s)

Since:

  • 0.1.0



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/lotus/action/mime.rb', line 60

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) }
      throw 406
    end
  end
end