class Switches::Cohort

Attributes

name[R]

Public Class Methods

collection(instance) click to toggle source
# File lib/switches/cohort.rb, line 7
def self.collection(instance)
  Collection.new(self, instance)
end
new(name, instance) click to toggle source
# File lib/switches/cohort.rb, line 11
def initialize(name, instance)
  @name = name
  @instance = instance
  @members = Set.new
end

Public Instance Methods

add(identifier) click to toggle source
# File lib/switches/cohort.rb, line 29
def add(identifier)
  @members.add(identifier.to_s)
  updated
end
as_json() click to toggle source
# File lib/switches/cohort.rb, line 46
def as_json
  {
    name: name,
    members: members
  }
end
include?(identifier) click to toggle source
# File lib/switches/cohort.rb, line 25
def include?(identifier)
  @members.include?(identifier.to_s)
end
inspect() click to toggle source
# 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() click to toggle source
# File lib/switches/cohort.rb, line 61
def key
  [type, name].join(":")
end
members() click to toggle source
# File lib/switches/cohort.rb, line 53
def members
  @members.to_a
end
reload() click to toggle source
# File lib/switches/cohort.rb, line 17
def reload
  if attributes = @instance.get(self)
    @members = attributes["members"].to_set
  end

  self
end
remove(identifier) click to toggle source
# File lib/switches/cohort.rb, line 34
def remove(identifier)
  @members.delete(identifier.to_s)
  updated
end
type() click to toggle source
# File lib/switches/cohort.rb, line 57
def type
  "cohort"
end

Private Instance Methods

updated() click to toggle source
# File lib/switches/cohort.rb, line 67
def updated
  @instance.set(self)
  @instance.notify(self)
  self
end