Class: Switches::Feature
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) ⇒ Feature
Returns a new instance of Feature.
11
12
13
14
15
16
|
# File 'lib/switches/feature.rb', line 11
def initialize(name, instance)
@name = name
@instance = instance
@percentage = Percentage(0)
@cohorts = Set.new
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
5
6
7
|
# File 'lib/switches/feature.rb', line 5
def name
@name
end
|
#percentage ⇒ Object
Returns the value of attribute percentage.
5
6
7
|
# File 'lib/switches/feature.rb', line 5
def percentage
@percentage
end
|
Class Method Details
.collection(instance) ⇒ Object
7
8
9
|
# File 'lib/switches/feature.rb', line 7
def self.collection(instance)
Collection.new(self, instance)
end
|
Instance Method Details
#add(cohort_name) ⇒ Object
37
38
39
40
|
# File 'lib/switches/feature.rb', line 37
def add(cohort_name)
@cohorts.add(cohort_name.to_s)
updated
end
|
#as_json ⇒ Object
53
54
55
56
57
58
59
|
# File 'lib/switches/feature.rb', line 53
def as_json
{
name: name,
percentage: percentage.to_i,
cohorts: @cohorts.to_a
}
end
|
#cohorts ⇒ Object
61
62
63
|
# File 'lib/switches/feature.rb', line 61
def cohorts
@cohorts.to_a
end
|
#inspect ⇒ Object
47
48
49
50
51
|
# File 'lib/switches/feature.rb', line 47
def inspect
output = "#<Feature #{@name}; #{@percentage}"
output += "; #{@cohorts.to_a.join(", ")}" if @cohorts.any?
output += ">"
end
|
#key ⇒ Object
75
76
77
|
# File 'lib/switches/feature.rb', line 75
def key
[type, name].join(":")
end
|
#off ⇒ Object
32
33
34
35
|
# File 'lib/switches/feature.rb', line 32
def off
@percentage = Percentage(0)
updated
end
|
#on(numeric = 100) ⇒ Object
27
28
29
30
|
# File 'lib/switches/feature.rb', line 27
def on(numeric = 100)
@percentage = Percentage(numeric)
updated
end
|
#on?(identifier) ⇒ Boolean
65
66
67
68
69
|
# File 'lib/switches/feature.rb', line 65
def on?(identifier)
return true if @percentage.max?
in_cohort?(identifier) || in_percentage?(identifier)
end
|
#reload ⇒ Object
18
19
20
21
22
23
24
25
|
# File 'lib/switches/feature.rb', line 18
def reload
if attributes = @instance.get(self)
@percentage = Percentage(attributes["percentage"])
@cohorts = attributes["cohorts"].to_set
end
self
end
|
#remove(cohort_name) ⇒ Object
42
43
44
45
|
# File 'lib/switches/feature.rb', line 42
def remove(cohort_name)
@cohorts.delete(cohort_name.to_s)
updated
end
|
#type ⇒ Object
71
72
73
|
# File 'lib/switches/feature.rb', line 71
def type
"feature"
end
|