Class: Request

Inherits:
Node
  • Object
show all
Defined in:
lib/rest.rb

Constant Summary collapse

@@id =
0

Instance Attribute Summary collapse

Attributes inherited from Node

#children, #level, #name, #parent

Instance Method Summary collapse

Methods inherited from Node

#add_child, #all_children, #print, #print_children, #root, #root?

Constructor Details

#initializeRequest

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

#idObject

Returns the value of attribute id.



127
128
129
# File 'lib/rest.rb', line 127

def id
  @id
end

#pathObject

Returns the value of attribute path.



127
128
129
# File 'lib/rest.rb', line 127

def path
  @path
end

#verbObject

Returns the value of attribute verb.



127
128
129
# File 'lib/rest.rb', line 127

def verb
  @verb
end

Instance Method Details

#hostObject



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

#parametersObject



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_sObject



137
138
139
140
# File 'lib/rest.rb', line 137

def to_s
  p = @path.gsub(/<([^>]*?)\??>=/, "\\1=")
  @verb + " " + p
end