Module: Observable

Included in:
DRb::Observable, Daemon, ObjectMonitor, ObservablePool::Observer, Spring
Defined in:
lib/observable.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/observable.rb', line 45

def self.included(klass)
  klass.module_eval do
    class << self
      unless method_defined?(:notifier_methods_visibility)
        def notifier_methods_visibility(visibility)
          send(visibility, *instance_methods)
        end
      end
    end
  end
end

Instance Method Details

#add_observers(*observers) ⇒ Object



14
15
16
# File 'lib/observable.rb', line 14

def add_observers(*observers)
  observers.each { |observer| add_observer(observer) }
end

#list_observersObject



26
27
28
29
30
31
32
# File 'lib/observable.rb', line 26

def list_observers
  if defined? @observer_peers
    @observer_peers.dup
  else
    []
  end
end

#notify_observer(observer, *arg, &block) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/observable.rb', line 34

def notify_observer(observer, *arg, &block)
  if defined? @observer_state and @observer_state
    if defined? @observer_peers
      if @observer_peers.include?(observer)
        observer.update(*arg, &block)
      end
    end
    @observer_state = false
  end
end

#observer?(observer) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
# File 'lib/observable.rb', line 18

def observer?(observer)
  if defined? @observer_peers
    @observer_peers.include?(observer)
  else
    false
  end
end