Class: Rack::Cors::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/cors/result.rb

Constant Summary collapse

HEADER_KEY =
'x-rack-cors'
MISS_NO_ORIGIN =
'no-origin'
MISS_NO_PATH =
'no-path'
MISS_NO_METHOD =
'no-method'
MISS_DENY_METHOD =
'deny-method'
MISS_DENY_HEADER =
'deny-header'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#hitObject

Returns the value of attribute hit.



15
16
17
# File 'lib/rack/cors/result.rb', line 15

def hit
  @hit
end

#miss_reasonObject

Returns the value of attribute miss_reason.



15
16
17
# File 'lib/rack/cors/result.rb', line 15

def miss_reason
  @miss_reason
end

#preflightObject

Returns the value of attribute preflight.



15
16
17
# File 'lib/rack/cors/result.rb', line 15

def preflight
  @preflight
end

Class Method Details

.hit(env) ⇒ Object



30
31
32
33
34
35
# File 'lib/rack/cors/result.rb', line 30

def self.hit(env)
  r = Result.new
  r.preflight = false
  r.hit = true
  env[Rack::Cors::ENV_KEY] = r
end

.miss(env, reason) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/rack/cors/result.rb', line 37

def self.miss(env, reason)
  r = Result.new
  r.preflight = false
  r.hit = false
  r.miss_reason = reason
  env[Rack::Cors::ENV_KEY] = r
end

.preflight(env) ⇒ Object



45
46
47
48
49
# File 'lib/rack/cors/result.rb', line 45

def self.preflight(env)
  r = Result.new
  r.preflight = true
  env[Rack::Cors::ENV_KEY] = r
end

Instance Method Details

#append_header(headers) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/rack/cors/result.rb', line 51

def append_header(headers)
  headers[HEADER_KEY] = if hit?
                          preflight? ? 'preflight-hit' : 'hit'
                        else
                          [
                            (preflight? ? 'preflight-miss' : 'miss'),
                            miss_reason
                          ].join('; ')
                        end
end

#hit?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/rack/cors/result.rb', line 17

def hit?
  !!hit
end

#miss(reason) ⇒ Object



25
26
27
28
# File 'lib/rack/cors/result.rb', line 25

def miss(reason)
  self.hit = false
  self.miss_reason = reason
end

#preflight?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/rack/cors/result.rb', line 21

def preflight?
  !!preflight
end