Class: Corosync::CPG::MemberList
- Inherits:
-
Object
- Object
- Corosync::CPG::MemberList
- Includes:
- Enumerable
- Defined in:
- lib/corosync/cpg/member_list.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#&(list) ⇒ Corosync::CPG::MemberList
Get a list of all members also present in another list.
-
#<<(member) ⇒ Object
Add a member to the list.
-
#delete(member) ⇒ void
Delete member from list.
-
#dup ⇒ Corosync::CPG::MemberList
Duplicate.
-
#each(&block) {|member| ... } ⇒ Object
Iterate over all the member objects in the list.
- #freeze ⇒ Corosync::CPG::MemberList
-
#initialize(*list) ⇒ MemberList
constructor
A new instance of MemberList.
-
#reason(member) ⇒ Symbol, ...
In the case of join/leave lists, this gets the reason a member is in the list.
-
#size ⇒ Integer
Number of members in list.
Constructor Details
#initialize(*list) ⇒ MemberList
Returns a new instance of MemberList.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/corosync/cpg/member_list.rb', line 15 def initialize(*list) @list = {} list = list[0] if list.size <= 1 if list.is_a?(Array) then list.each do |recipient| self << recipient end elsif list.is_a?(Corosync::CPG::Member) then self << list elsif list.nil? then # nothing else raise ArgumentError, "Invalid recipient type: #{list.class}" end end |
Class Method Details
.new(*list) ⇒ Object
10 11 12 13 14 |
# File 'lib/corosync/cpg/member_list.rb', line 10 def self.new(*list) # return the input list if we were passed a MemberList return list[0] if list.size == 1 and list[0].is_a?(self) super end |
Instance Method Details
#&(list) ⇒ Corosync::CPG::MemberList
Get a list of all members also present in another list
60 61 62 |
# File 'lib/corosync/cpg/member_list.rb', line 60 def &(list) @list.keys & list.to_a end |
#<<(member) ⇒ Object
Add a member to the list
35 36 37 38 39 40 41 42 |
# File 'lib/corosync/cpg/member_list.rb', line 35 def << (member) if member.is_a?(FFI::Pointer) then cpgaddress = Corosync::CpgAddress.new(member) @list[Corosync::CPG::Member.new(cpgaddress)] = cpgaddress[:reason] else @list[member] = nil end end |
#delete(member) ⇒ void
This method returns an undefined value.
Delete member from list
67 68 69 |
# File 'lib/corosync/cpg/member_list.rb', line 67 def delete(member) @list.delete(member) end |
#dup ⇒ Corosync::CPG::MemberList
Duplicate
73 74 75 76 77 78 79 |
# File 'lib/corosync/cpg/member_list.rb', line 73 def dup new = self.class.new self.each do |member| new << member.dup end new end |
#each(&block) {|member| ... } ⇒ Object
Iterate over all the member objects in the list.
53 54 55 |
# File 'lib/corosync/cpg/member_list.rb', line 53 def each(&block) @list.each_key &block end |
#freeze ⇒ Corosync::CPG::MemberList
95 96 97 98 |
# File 'lib/corosync/cpg/member_list.rb', line 95 def freeze @list.freeze self end |
#reason(member) ⇒ Symbol, ...
In the case of join/leave lists, this gets the reason a member is in the list.
89 90 91 92 |
# File 'lib/corosync/cpg/member_list.rb', line 89 def reason(member) member = Corosync::CPG::Member.new if !member.is_a?(Corosync::CPG::Member) @list[member] end |
#size ⇒ Integer
Number of members in list
46 47 48 |
# File 'lib/corosync/cpg/member_list.rb', line 46 def size @list.size end |