Class: CapProxy::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/cap_proxy/filter.rb

Direct Known Subclasses

RulesEngine

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_hash(hash) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/cap_proxy/filter.rb', line 7

def self.from_hash(hash)
  RulesEngine.new(
    hash.each_pair.map do |param, value|
      case param
      when :method
        [ [ :method, value.upcase ] ]
      when :path
        case value
        when Regexp
          [ [ :path_regexp, value ] ]
        when String
          [ [ :path, value ] ]
        else
          raise InvalidFilterParam.new("Invalid value #{value.inspect} for :path")
        end
      when :headers
        value.each_pair.map do |header, value|
          case value
          when String
            [ :header, header.downcase, value ]
          when Regexp
            [ :header_regexp, header.downcase, value ]
          else
            raise InvalidRule.new("Invalid header rule #{value.inspect}")
          end
        end
      else
        raise InvalidFilterParam.new("Invalid item #{param.inspect}")
      end
    end.inject {|a, b| a.concat(b)}
  )
end

Instance Method Details

#apply?(request) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


40
41
42
# File 'lib/cap_proxy/filter.rb', line 40

def apply?(request)
  raise NotImplementedError.new("apply? has to be implemented by inherited classes")
end