Class: SslEnforcerConstraint

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/ssl-enforcer/constraint.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, rule, request) ⇒ SslEnforcerConstraint

Returns a new instance of SslEnforcerConstraint.



2
3
4
5
6
# File 'lib/rack/ssl-enforcer/constraint.rb', line 2

def initialize(name, rule, request)
  @name    = name
  @rule    = rule
  @request = request
end

Instance Method Details

#matches?Boolean

Returns:

  • (Boolean)


8
9
10
11
12
13
14
15
16
17
18
# File 'lib/rack/ssl-enforcer/constraint.rb', line 8

def matches?
  if @rule.is_a?(String) && [:only, :except].include?(@name)
    result = tested_string[0, @rule.size].send(operator, @rule)
  elsif @rule.respond_to?(:call)
    result = @rule.call(@request)
  else
    result = tested_string.send(operator, @rule)
  end

  negate_result? ? !result : result
end