Class: CouchProxy::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/couchproxy/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, partitions) ⇒ Node

Returns a new instance of Node.



7
8
9
10
11
# File 'lib/couchproxy/node.rb', line 7

def initialize(uri, partitions)
  parsed = URI.parse(uri)
  @uri, @host, @port = uri, parsed.host, parsed.port
  @partitions = partitions.map {|num| Partition.new(self, num) }
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



5
6
7
# File 'lib/couchproxy/node.rb', line 5

def host
  @host
end

#partitionsObject (readonly)

Returns the value of attribute partitions.



5
6
7
# File 'lib/couchproxy/node.rb', line 5

def partitions
  @partitions
end

#portObject (readonly)

Returns the value of attribute port.



5
6
7
# File 'lib/couchproxy/node.rb', line 5

def port
  @port
end

#uriObject (readonly)

Returns the value of attribute uri.



5
6
7
# File 'lib/couchproxy/node.rb', line 5

def uri
  @uri
end

Instance Method Details

#any_partitionObject



21
22
23
# File 'lib/couchproxy/node.rb', line 21

def any_partition
  @partitions[rand(@partitions.size)]
end

#hosts?(partition) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/couchproxy/node.rb', line 13

def hosts?(partition)
  @partitions.any? {|p| p.num == partition }
end

#partition(num) ⇒ Object



17
18
19
# File 'lib/couchproxy/node.rb', line 17

def partition(num)
  @partitions.find {|p| p.num == num }
end