Module: Otto::Static
Instance Method Summary collapse
-
#indifferent_hash ⇒ Object
Creates a Hash with indifferent access.
-
#indifferent_params(params) ⇒ Object
Enable string or symbol key access to the nested params hash.
- #not_found ⇒ Object
- #server_error ⇒ Object
Instance Method Details
#indifferent_hash ⇒ Object
Creates a Hash with indifferent access.
31 32 33 |
# File 'lib/otto/static.rb', line 31 def indifferent_hash Hash.new {|hash,key| hash[key.to_s] if Symbol === key } end |
#indifferent_params(params) ⇒ Object
Enable string or symbol key access to the nested params hash.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/otto/static.rb', line 13 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_found ⇒ Object
9 10 11 |
# File 'lib/otto/static.rb', line 9 def not_found [404, {'Content-Type'=>'text/plain'}, ["Not Found"]] end |
#server_error ⇒ Object
6 7 8 |
# File 'lib/otto/static.rb', line 6 def server_error [500, {'Content-Type'=>'text/plain'}, ["Server error"]] end |