Class: WingedCouch::HttpPath

Inherits:
Object
  • Object
show all
Defined in:
lib/winged_couch/http_path.rb

Overview

Class for storing URL path

Constant Summary collapse

DEFAULT_LEVEL =
:server

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host = WingedCouch.url) ⇒ HttpPath

Returns a new instance of HttpPath


10
11
12
13
14
# File 'lib/winged_couch/http_path.rb', line 10

def initialize(host = WingedCouch.url)
  @host = without_slashes(host.to_s)
  @path = []
  @level = DEFAULT_LEVEL
end

Instance Attribute Details

#hostObject

Returns the value of attribute host


8
9
10
# File 'lib/winged_couch/http_path.rb', line 8

def host
  @host
end

#levelObject

Returns the value of attribute level


8
9
10
# File 'lib/winged_couch/http_path.rb', line 8

def level
  @level
end

#pathObject

Returns the value of attribute path


8
9
10
# File 'lib/winged_couch/http_path.rb', line 8

def path
  @path
end

Class Method Details

.join(path, level = DEFAULT_LEVEL) ⇒ Object

Returns new HttpPath instance with joined path

Parameters:

  • path (String, Symbol)

Returns:

  • path


43
44
45
# File 'lib/winged_couch/http_path.rb', line 43

def self.join(path, level = DEFAULT_LEVEL)
  new.join(path, level)
end

Instance Method Details

#==(other) ⇒ Object


56
57
58
# File 'lib/winged_couch/http_path.rb', line 56

def ==(other)
  other.is_a?(self.class) && host == other.host && path == other.path
end

#join(path, level = DEFAULT_LEVEL) ⇒ WingedCouch::HttpPath

Returns new HttpPath instance with joined path

Parameters:

  • path (String, Symbol)

Returns:


34
35
36
# File 'lib/winged_couch/http_path.rb', line 34

def join(path, level = DEFAULT_LEVEL)
  dup.join!(path, level)
end

#join!(path, level = DEFAULT_LEVEL) ⇒ WingedCouch::HttpPath

Joins current path with passed

Parameters:

  • path (String, Symbol)

Returns:


22
23
24
25
26
# File 'lib/winged_couch/http_path.rb', line 22

def join!(path, level = DEFAULT_LEVEL)
  @path << without_slashes(path.to_s)
  @level = level
  self
end

#to_sString

Returns string representation of http path

Returns:

  • (String)

51
52
53
# File 'lib/winged_couch/http_path.rb', line 51

def to_s
  args.join("/")
end