Class: ZK::Group::Member
- Inherits:
-
Object
- Object
- ZK::Group::Member
- Includes:
- Common
- Defined in:
- lib/zk-group/member.rb
Instance Attribute Summary collapse
-
#group ⇒ Group
readonly
The group instance this member belongs to.
-
#name ⇒ String
readonly
The relative path of this member under ‘group.path`.
-
#path ⇒ String
readonly
The absolute path of this member.
-
#zk ⇒ Object
readonly
Returns the value of attribute zk.
Instance Method Summary collapse
-
#active? ⇒ Boolean
probably poor choice of name, but does this member still an active membership to its group (i.e. is its path still good).
- #data ⇒ Object
- #data=(data) ⇒ Object
-
#initialize(zk, group, path) ⇒ Member
constructor
A new instance of Member.
-
#leave ⇒ Object
Leave the group this membership is associated with.
Constructor Details
#initialize(zk, group, path) ⇒ Member
Returns a new instance of Member.
17 18 19 20 21 22 23 |
# File 'lib/zk-group/member.rb', line 17 def initialize(zk, group, path) @zk = zk @group = group @path = path @name = File.basename(@path) @mutex = Mutex.new end |
Instance Attribute Details
#group ⇒ Group (readonly)
Returns the group instance this member belongs to.
9 10 11 |
# File 'lib/zk-group/member.rb', line 9 def group @group end |
#name ⇒ String (readonly)
Returns the relative path of this member under ‘group.path`.
12 13 14 |
# File 'lib/zk-group/member.rb', line 12 def name @name end |
#path ⇒ String (readonly)
Returns the absolute path of this member.
15 16 17 |
# File 'lib/zk-group/member.rb', line 15 def path @path end |
#zk ⇒ Object (readonly)
Returns the value of attribute zk.
6 7 8 |
# File 'lib/zk-group/member.rb', line 6 def zk @zk end |
Instance Method Details
#active? ⇒ Boolean
probably poor choice of name, but does this member still an active membership to its group (i.e. is its path still good).
This will return false after leave is called.
29 30 31 |
# File 'lib/zk-group/member.rb', line 29 def active? zk.exists?(path) end |
#data ⇒ Object
41 42 43 |
# File 'lib/zk-group/member.rb', line 41 def data @data ||= zk.get(path).first end |
#data=(data) ⇒ Object
45 46 47 48 49 |
# File 'lib/zk-group/member.rb', line 45 def data=(data) @data = data zk.set(path, data) data end |
#leave ⇒ Object
Leave the group this membership is associated with. In the basic implementation, this is not meant to kick another member out of the group.
37 38 39 |
# File 'lib/zk-group/member.rb', line 37 def leave zk.delete(path) end |