Class: Switches::Cohort
Constant Summary
JSONSerializer::ParserError
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
deserialize, serialize, #to_json
Constructor Details
#initialize(name, instance) ⇒ Cohort
Returns a new instance of Cohort.
11
12
13
14
15
|
# File 'lib/switches/cohort.rb', line 11
def initialize(name, instance)
@name = name
@instance = instance
@members = Set.new
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
5
6
7
|
# File 'lib/switches/cohort.rb', line 5
def name
@name
end
|
Class Method Details
.collection(instance) ⇒ Object
7
8
9
|
# File 'lib/switches/cohort.rb', line 7
def self.collection(instance)
Collection.new(self, instance)
end
|
Instance Method Details
#add(identifier) ⇒ Object
29
30
31
32
|
# File 'lib/switches/cohort.rb', line 29
def add(identifier)
@members.add(identifier.to_s)
updated
end
|
#as_json ⇒ Object
46
47
48
49
50
51
|
# File 'lib/switches/cohort.rb', line 46
def as_json
{
name: name,
members: members
}
end
|
#include?(identifier) ⇒ Boolean
25
26
27
|
# File 'lib/switches/cohort.rb', line 25
def include?(identifier)
@members.include?(identifier.to_s)
end
|
#inspect ⇒ Object
39
40
41
42
43
44
|
# File 'lib/switches/cohort.rb', line 39
def inspect
output = "#<Cohort #{@name}"
output += "; #{@members.count} member"
output += "s" unless @members.count == 1
output += ">"
end
|
#key ⇒ Object
61
62
63
|
# File 'lib/switches/cohort.rb', line 61
def key
[type, name].join(":")
end
|
#members ⇒ Object
53
54
55
|
# File 'lib/switches/cohort.rb', line 53
def members
@members.to_a
end
|
#reload ⇒ Object
17
18
19
20
21
22
23
|
# File 'lib/switches/cohort.rb', line 17
def reload
if attributes = @instance.get(self)
@members = attributes["members"].to_set
end
self
end
|
#remove(identifier) ⇒ Object
34
35
36
37
|
# File 'lib/switches/cohort.rb', line 34
def remove(identifier)
@members.delete(identifier.to_s)
updated
end
|
#type ⇒ Object
57
58
59
|
# File 'lib/switches/cohort.rb', line 57
def type
"cohort"
end
|