Class: Rack::Accept::Context
- Inherits:
-
Object
- Object
- Rack::Accept::Context
- Defined in:
- lib/rack/accept/context.rb
Overview
Implements the Rack middleware interface.
Defined Under Namespace
Classes: AcceptError
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
Instance Method Summary collapse
-
#call(env) ⇒ Object
Inserts a new Rack::Accept::Request object into the environment before handing the request to the app immediately downstream.
-
#charsets=(charsets) ⇒ Object
Defines the character sets this server is able to serve.
-
#encodings=(encodings) ⇒ Object
Defines the types of encodings this server is able to serve.
-
#initialize(app) {|_self| ... } ⇒ Context
constructor
A new instance of Context.
-
#languages=(languages) ⇒ Object
Defines the languages this server is able to serve.
-
#media_types=(media_types) ⇒ Object
Defines the types of media this server is able to serve.
Constructor Details
#initialize(app) {|_self| ... } ⇒ Context
Returns a new instance of Context.
10 11 12 13 14 15 |
# File 'lib/rack/accept/context.rb', line 10 def initialize(app) @app = app @checks = {} @check_headers = [] yield self if block_given? end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
8 9 10 |
# File 'lib/rack/accept/context.rb', line 8 def app @app end |
Instance Method Details
#call(env) ⇒ Object
Inserts a new Rack::Accept::Request object into the environment before handing the request to the app immediately downstream.
19 20 21 22 23 24 25 26 27 |
# File 'lib/rack/accept/context.rb', line 19 def call(env) request = env['rack-accept.request'] ||= Request.new(env) check!(request) unless @checks.empty? @app.call(env) rescue AcceptError response = Response.new response.not_acceptable! response.finish end |
#charsets=(charsets) ⇒ Object
Defines the character sets this server is able to serve.
35 36 37 |
# File 'lib/rack/accept/context.rb', line 35 def charsets=(charsets) add_check(:charset, charsets) end |
#encodings=(encodings) ⇒ Object
Defines the types of encodings this server is able to serve.
40 41 42 |
# File 'lib/rack/accept/context.rb', line 40 def encodings=(encodings) add_check(:encoding, encodings) end |
#languages=(languages) ⇒ Object
Defines the languages this server is able to serve.
45 46 47 |
# File 'lib/rack/accept/context.rb', line 45 def languages=(languages) add_check(:language, languages) end |
#media_types=(media_types) ⇒ Object
Defines the types of media this server is able to serve.
30 31 32 |
# File 'lib/rack/accept/context.rb', line 30 def media_types=(media_types) add_check(:media_type, media_types) end |