class Switches::Instance

Attributes

node_id[R]

Public Class Methods

new(configuration) click to toggle source
# File lib/switches/instance.rb, line 7
def initialize(configuration)
  @url = configuration.backend
  @node_id = SecureRandom.hex(3)

  mon_initialize
end

Public Instance Methods

clear() click to toggle source
# File lib/switches/instance.rb, line 54
def clear
  backend.clear
end
cohort(name) click to toggle source
# File lib/switches/instance.rb, line 29
def cohort(name)
  synchronize do
    cohorts[name]
  end
end
feature(name) click to toggle source
# File lib/switches/instance.rb, line 23
def feature(name)
  synchronize do
    features[name]
  end
end
get(item) click to toggle source
# File lib/switches/instance.rb, line 35
def get(item)
  backend.get(item)
end
inspect() click to toggle source
# File lib/switches/instance.rb, line 58
def inspect
  "#<Switches #{@url}>"
end
notified(update) click to toggle source
# File lib/switches/instance.rb, line 48
def notified(update)
  unless update.from?(node_id)
    collections[update.type].reload(update.name)
  end
end
notify(item) click to toggle source
# File lib/switches/instance.rb, line 43
def notify(item)
  update = Update.build(item, node_id)
  backend.notify(update)
end
set(item) click to toggle source
# File lib/switches/instance.rb, line 39
def set(item)
  backend.set(item)
end
start() click to toggle source
# File lib/switches/instance.rb, line 14
def start
  backend.listen
  self
end
stop() click to toggle source
# File lib/switches/instance.rb, line 19
def stop
  backend.stop
end

Private Instance Methods

backend() click to toggle source
# File lib/switches/instance.rb, line 64
def backend
  @backend ||= Backend.factory(@url, self)
end
cohorts() click to toggle source
# File lib/switches/instance.rb, line 72
def cohorts
  @cohorts ||= Cohort.collection(self)
end
collections() click to toggle source
# File lib/switches/instance.rb, line 76
def collections
  {
    "feature" => features,
    "cohort" => cohorts
  }
end
features() click to toggle source
# File lib/switches/instance.rb, line 68
def features
  @features ||= Feature.collection(self)
end