Module: Observable

Defined in:
lib/red_query/observable.rb

Instance Method Summary collapse

Instance Method Details

#add_observer(observer) ⇒ Object



2
3
4
5
# File 'lib/red_query/observable.rb', line 2

def add_observer(observer)
  @_observers = [] unless @_observers
  @_observers.push(observer)
end

#changed(state = true) ⇒ Object



7
8
9
# File 'lib/red_query/observable.rb', line 7

def changed(state=true)
  @_observe_state = state
end

#changed?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/red_query/observable.rb', line 11

def changed?
  !!@_observe_state
end

#count_observersObject



15
16
17
18
# File 'lib/red_query/observable.rb', line 15

def count_observers
  return @_observers.size if @_observers
  0
end

#delete_observer(observer) ⇒ Object



24
25
26
27
# File 'lib/red_query/observable.rb', line 24

def delete_observer(observer)
  return unless @_observers
  @_observers.delete(observer)
end

#delete_observersObject



20
21
22
# File 'lib/red_query/observable.rb', line 20

def delete_observers
  @_observers = []
end

#notify_observers(a, b, c, d, e, f, g, h) ⇒ Object



29
30
31
32
33
# File 'lib/red_query/observable.rb', line 29

def notify_observers(a, b, c, d, e, f, g, h)
  return unless @_observers
  @_observers.each { |o| o.update(a, b, c, d, e, f, g, h) }
  @_observe_state = false
end