Module: Otto::Static

Extended by:
Static
Included in:
Static
Defined in:
lib/otto/static.rb

Instance Method Summary collapse

Instance Method Details

#indifferent_hashObject

Creates a Hash with indifferent access.



45
46
47
# File 'lib/otto/static.rb', line 45

def indifferent_hash
  Hash.new { |hash, key| hash[key.to_s] if key.is_a?(Symbol) }
end

#indifferent_params(params) ⇒ Object

Enable string or symbol key access to the nested params hash.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/otto/static.rb', line 25

def indifferent_params(params)
  if params.is_a?(Hash)
    params = indifferent_hash.merge(params)
    params.each do |key, value|
      next unless value.is_a?(Hash) || value.is_a?(Array)

      params[key] = indifferent_params(value)
    end
  elsif params.is_a?(Array)
    params.collect! do |value|
      if value.is_a?(Hash) || value.is_a?(Array)
        indifferent_params(value)
      else
        value
      end
    end
  end
end

#not_foundObject



11
12
13
# File 'lib/otto/static.rb', line 11

def not_found
  [404, security_headers.merge({ 'content-type' => 'text/plain' }), ['Not Found']]
end

#security_headersObject



15
16
17
18
19
20
21
22
# File 'lib/otto/static.rb', line 15

def security_headers
  {
    'x-frame-options' => 'DENY',
    'x-content-type-options' => 'nosniff',
    'x-xss-protection' => '1; mode=block',
    'referrer-policy' => 'strict-origin-when-cross-origin'
  }
end

#server_errorObject



7
8
9
# File 'lib/otto/static.rb', line 7

def server_error
  [500, security_headers.merge({ 'content-type' => 'text/plain' }), ['Server error']]
end