Class: Switcher::Spec

Inherits:
Object
  • Object
show all
Defined in:
lib/switcher/spec.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Spec

Returns a new instance of Spec.



6
7
8
9
10
11
# File 'lib/switcher/spec.rb', line 6

def initialize(name, options={})
  @name        = name.to_sym
  @states      = {}
  @states_list = []
  @targets     = []
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



13
14
15
# File 'lib/switcher/spec.rb', line 13

def name
  @name
end

#statesObject (readonly)

Returns the value of attribute states.



13
14
15
# File 'lib/switcher/spec.rb', line 13

def states
  @states
end

#states_listObject (readonly)

Returns the value of attribute states_list.



13
14
15
# File 'lib/switcher/spec.rb', line 13

def states_list
  @states_list
end

#targetsObject (readonly)

Returns the value of attribute targets.



13
14
15
# File 'lib/switcher/spec.rb', line 13

def targets
  @targets
end

Instance Method Details

#notify(*list) ⇒ Object



23
24
25
# File 'lib/switcher/spec.rb', line 23

def notify(*list)
  @targets = list
end

#state(name, &block) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/switcher/spec.rb', line 15

def state(name, &block)
  listener = Listener.new(name)
  listener.instance_eval(&block) if block_given?

  @states_list << name.to_sym
  @states[name.to_sym] = listener
end