Class: Waves::Matchers::Accept

Inherits:
Object
  • Object
show all
Defined in:
lib/waves/matchers/accept.rb

Overview

TODO:

Rename to Negotiation? –rue

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Accept

Set up Accept parsing.

Only the defined constraints are included.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/waves/matchers/accept.rb', line 12

def initialize(options)
  
  @constraints = {}
  
  { :accept => :accept, :charset => :accept_charset, :lang => :accept_lang }.each { |key,method|
    if options[key]
      if options[key].is_a? Array
        @constraints[method] = options[key] unless options[key].empty?
      else
        @constraints[method] = [ options[key] ]
      end
    end
  }
  
end

Instance Method Details

#[](request) ⇒ Object

Proc-like interface



38
39
40
# File 'lib/waves/matchers/accept.rb', line 38

def [](request)
  call request
end

#call(request) ⇒ Object

Verify that any and all Accept constraints match.

Request handles these.



32
33
34
# File 'lib/waves/matchers/accept.rb', line 32

def call(request)
  @constraints.all? { |key, val| request.send(key).include? val }
end