Class: Restfulness::Path

Inherits:
Object
  • Object
show all
Defined in:
lib/restfulness/path.rb

Overview

The Path object is provided in request objects to provide easy access to parameters included in the URI’s path.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(route, string) ⇒ Path

Returns a new instance of Path.



10
11
12
13
14
# File 'lib/restfulness/path.rb', line 10

def initialize(route, string)
  self.route  = route
  self.params = {}
  parse(string)
end

Instance Attribute Details

#componentsObject

Returns the value of attribute components.



8
9
10
# File 'lib/restfulness/path.rb', line 8

def components
  @components
end

#paramsObject

Returns the value of attribute params.



8
9
10
# File 'lib/restfulness/path.rb', line 8

def params
  @params
end

#routeObject

Returns the value of attribute route.



8
9
10
# File 'lib/restfulness/path.rb', line 8

def route
  @route
end

Instance Method Details

#[](index) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/restfulness/path.rb', line 20

def [](index)
  if index.is_a?(Integer)
    components[index]
  else
    params[index]
  end
end

#to_sObject



16
17
18
# File 'lib/restfulness/path.rb', line 16

def to_s
  '/' + components.join('/')
end