Class: Request
Constant Summary collapse
- @@id =
0
Instance Attribute Summary collapse
-
#id ⇒ Object
Returns the value of attribute id.
-
#path ⇒ Object
Returns the value of attribute path.
-
#verb ⇒ Object
Returns the value of attribute verb.
Attributes inherited from Node
#children, #level, #name, #parent
Instance Method Summary collapse
- #host ⇒ Object
-
#initialize ⇒ Request
constructor
A new instance of Request.
- #parameters ⇒ Object
- #to_s ⇒ Object
Methods inherited from Node
#add_child, #all_children, #print, #print_children, #root, #root?
Constructor Details
#initialize ⇒ Request
Returns a new instance of Request.
131 132 133 134 135 |
# File 'lib/rest.rb', line 131 def initialize @id = @@id; @@id += 1 super() end |
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
127 128 129 |
# File 'lib/rest.rb', line 127 def id @id end |
#path ⇒ Object
Returns the value of attribute path.
127 128 129 |
# File 'lib/rest.rb', line 127 def path @path end |
#verb ⇒ Object
Returns the value of attribute verb.
127 128 129 |
# File 'lib/rest.rb', line 127 def verb @verb end |
Instance Method Details
#host ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/rest.rb', line 168 def host node = self while( node ) node.children.each do |c| if c.is_a? Host return c end end node = node.parent end nil end |
#parameters ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/rest.rb', line 142 def parameters result = Array.new @path.scan( /[^=]<(.*?)(\??)>/ ) do |p| node = self found = false optional = $2.empty? ? false : true while( node && !found ) node.children.each do |c| if ( c.is_a?( Parameter ) && c.name == $1 ) c.optional = optional result.push c found = true break end end node = node.parent end if ( !found ) n = Parameter.new( $1 ) n.optional = optional result.push n end end result end |
#to_s ⇒ Object
137 138 139 140 |
# File 'lib/rest.rb', line 137 def to_s p = @path.gsub(/<([^>]*?)\??>=/, "\\1=") @verb + " " + p end |