Class: Rack::Prefer::PreferPresenter
- Inherits:
-
Object
- Object
- Rack::Prefer::PreferPresenter
- Defined in:
- lib/rack/prefer.rb
Instance Attribute Summary collapse
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Instance Method Summary collapse
- #handling ⇒ Object
- #handling_lanient? ⇒ Boolean
- #handling_strict? ⇒ Boolean
-
#initialize(req) ⇒ PreferPresenter
constructor
A new instance of PreferPresenter.
- #respond_async? ⇒ Boolean
- #return ⇒ Object
- #return_minimal? ⇒ Boolean
- #return_representaton? ⇒ Boolean
- #wait ⇒ Object
- #wait? ⇒ Boolean
Constructor Details
#initialize(req) ⇒ PreferPresenter
Returns a new instance of PreferPresenter.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/rack/prefer.rb', line 8 def initialize(req) @values = CGI.parse( (req.env['HTTP_PREFER'] || '').gsub(',','&').gsub(' ','') ) @values = {} if !@values.is_a?(Hash) @values.each{|k,v| @values[k] = v.first} if Object.const_defined?(:HashWithIndifferentAccess) @values = HashWithIndifferentAccess.new(@values) end end |
Instance Attribute Details
#values ⇒ Object (readonly)
Returns the value of attribute values.
6 7 8 |
# File 'lib/rack/prefer.rb', line 6 def values @values end |
Instance Method Details
#handling ⇒ Object
43 44 45 |
# File 'lib/rack/prefer.rb', line 43 def handling @values['handling'] end |
#handling_lanient? ⇒ Boolean
51 52 53 |
# File 'lib/rack/prefer.rb', line 51 def handling_lanient? @values['handling'] == 'lanient' end |
#handling_strict? ⇒ Boolean
47 48 49 |
# File 'lib/rack/prefer.rb', line 47 def handling_strict? @values['handling'] == 'strict' end |
#respond_async? ⇒ Boolean
27 28 29 |
# File 'lib/rack/prefer.rb', line 27 def respond_async? @values.key?('respond-async') end |
#return ⇒ Object
31 32 33 |
# File 'lib/rack/prefer.rb', line 31 def return @values['return'] end |
#return_minimal? ⇒ Boolean
39 40 41 |
# File 'lib/rack/prefer.rb', line 39 def return_minimal? @values['return'] == 'minimal' end |
#return_representaton? ⇒ Boolean
35 36 37 |
# File 'lib/rack/prefer.rb', line 35 def return_representaton? @values['return'] == 'representation' end |
#wait ⇒ Object
23 24 25 |
# File 'lib/rack/prefer.rb', line 23 def wait @values['wait'].to_i end |
#wait? ⇒ Boolean
19 20 21 |
# File 'lib/rack/prefer.rb', line 19 def wait? @values.key?('wait') end |