Class: Switches::Instance

Inherits:
Object
  • Object
show all
Includes:
MonitorMixin
Defined in:
lib/switches/instance.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ Instance

Returns a new instance of Instance.



7
8
9
10
11
12
# File 'lib/switches/instance.rb', line 7

def initialize(configuration)
  @url = configuration.backend
  @node_id = SecureRandom.hex(3)

  mon_initialize
end

Instance Attribute Details

#node_idObject (readonly)

Returns the value of attribute node_id.



5
6
7
# File 'lib/switches/instance.rb', line 5

def node_id
  @node_id
end

Instance Method Details

#clearObject



54
55
56
# File 'lib/switches/instance.rb', line 54

def clear
  backend.clear
end

#cohort(name) ⇒ Object



29
30
31
32
33
# File 'lib/switches/instance.rb', line 29

def cohort(name)
  synchronize do
    cohorts[name]
  end
end

#feature(name) ⇒ Object



23
24
25
26
27
# File 'lib/switches/instance.rb', line 23

def feature(name)
  synchronize do
    features[name]
  end
end

#get(item) ⇒ Object



35
36
37
# File 'lib/switches/instance.rb', line 35

def get(item)
  backend.get(item)
end

#inspectObject



58
59
60
# File 'lib/switches/instance.rb', line 58

def inspect
  "#<Switches #{@url}>"
end

#notified(update) ⇒ Object



48
49
50
51
52
# 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) ⇒ Object



43
44
45
46
# File 'lib/switches/instance.rb', line 43

def notify(item)
  update = Update.build(item, node_id)
  backend.notify(update)
end

#set(item) ⇒ Object



39
40
41
# File 'lib/switches/instance.rb', line 39

def set(item)
  backend.set(item)
end

#startObject



14
15
16
17
# File 'lib/switches/instance.rb', line 14

def start
  backend.listen
  self
end

#stopObject



19
20
21
# File 'lib/switches/instance.rb', line 19

def stop
  backend.stop
end