Class: Mentawai::Core::Input
- Inherits:
-
Object
- Object
- Mentawai::Core::Input
- Defined in:
- lib/mentawai/core/input.rb
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Instance Method Summary collapse
- #get(key) ⇒ Object (also: #[])
- #getHeader(key) ⇒ Object
- #getProperty(prop) ⇒ Object (also: #getProp, #get_prop, #get_property, #property, #prop)
- #hasKey?(key) ⇒ Boolean (also: #has_key?, #key?)
- #hasProperty?(prop) ⇒ Boolean (also: #has_property?, #has_prop?, #hasProp?)
- #headers ⇒ Object
-
#initialize(req) ⇒ Input
constructor
A new instance of Input.
- #keys ⇒ Object
- #put(key, value) ⇒ Object (also: #[]=)
- #remove(key) ⇒ Object
- #values ⇒ Object (also: #each)
Constructor Details
#initialize(req) ⇒ Input
Returns a new instance of Input.
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/mentawai/core/input.rb', line 8 def initialize(req) @request = req # Copy params... @params = Hash.new req.params.each { |k,v| @params[k] = v } # Copy headers... @headers = Hash.new req.env.each do |k,v| @headers[k] = v if k =~ /^HTTP_/ # Begin with HTTP end end |
Instance Attribute Details
#request ⇒ Object (readonly)
Returns the value of attribute request.
6 7 8 |
# File 'lib/mentawai/core/input.rb', line 6 def request @request end |
Instance Method Details
#get(key) ⇒ Object Also known as: []
22 23 24 |
# File 'lib/mentawai/core/input.rb', line 22 def get(key) @params[key] end |
#getHeader(key) ⇒ Object
34 35 36 |
# File 'lib/mentawai/core/input.rb', line 34 def getHeader(key) @headers[key] end |
#getProperty(prop) ⇒ Object Also known as: getProp, get_prop, get_property, property, prop
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/mentawai/core/input.rb', line 72 def getProperty(prop) # Try env... return @request.env[prop] if @request.env.key?(prop) # Capitalize? return @request.env[prop.upcase] if @request.env.key?(prop.upcase) # Nothing found... nil end |
#hasKey?(key) ⇒ Boolean Also known as: has_key?, key?
54 55 56 |
# File 'lib/mentawai/core/input.rb', line 54 def hasKey?(key) @params.has_key?(key) end |
#hasProperty?(prop) ⇒ Boolean Also known as: has_property?, has_prop?, hasProp?
61 62 63 64 65 66 |
# File 'lib/mentawai/core/input.rb', line 61 def hasProperty?(prop) @request.class.public_instance_methods.each do |m| return 1 if m == prop end nil end |
#headers ⇒ Object
38 39 40 |
# File 'lib/mentawai/core/input.rb', line 38 def headers @headers end |
#keys ⇒ Object
42 43 44 45 46 |
# File 'lib/mentawai/core/input.rb', line 42 def keys @params.each do |k,v| yield k end end |
#put(key, value) ⇒ Object Also known as: []=
26 27 28 |
# File 'lib/mentawai/core/input.rb', line 26 def put(key, value) @params[key] = value end |
#remove(key) ⇒ Object
30 31 32 |
# File 'lib/mentawai/core/input.rb', line 30 def remove(key) @params.delete(key) end |
#values ⇒ Object Also known as: each
48 49 50 51 52 |
# File 'lib/mentawai/core/input.rb', line 48 def values @params.each do |k,v| yield k,v end end |