class NodeObserver
NodeObserver
. @class_description
A NodeObserver library implementation.
@attr observing [Set]
Subjects.
@attr changed [Set]
Changed subjects.
NodeObserver
. @class_description
A NodeObserver library implementation.
@attr observing [Set]
Subjects.
@attr changed [Set]
Changed subjects.
Constants
- VERSION
Public Class Methods
self.instance(). @description
Gets instance. Lazily initializes instance.
@return [NodeObserver]
The instance.
# File lib/node_observer_impl.rb, line 20 def self.instance() if (@instance.nil?()) self.instance = new() end return @instance end
Private Class Methods
self.instance=(singleton = nil). @description
Sets the singleton instance.
@param singleton [NodeObserver]
The instance.
@return [NodeObserver]
The argument.
# File lib/node_observer_impl.rb, line 225 def self.instance=(singleton = nil) @instance = singleton return @instance end
initialize(). @description
Initializes the singleton instance's instance variables.
# File lib/node_observer_impl.rb, line 213 def initialize() self.observing = Set[] self.changed = Set[] end
Public Instance Methods
add(n = nil). @description
Adds observing a subject.
@param n [Node]
The addition.
@return [NilClass]
nil.
# File lib/node_observer_impl.rb, line 70 def add(n = nil) unless (n.instance_of?(Node)) raise(ArgumentError, "#{n} is not a Node instance.") else observing().add(n) end return nil end
changed_node
(subject = nil). @description
Predicate. Verifies a subject was changed.
@param subject [Node]
Any instance.
@return [TrueClass, FalseClass]
True in the case the argument is a 'changed' element. False otherwise.
# File lib/node_observer_impl.rb, line 47 def changed_node(subject = nil) return (changed().include?(subject)) end
remove(n = nil). @description
Removes a subject.
@param n [Node]
The removal.
@return [NilClass]
nil.
# File lib/node_observer_impl.rb, line 88 def remove(n = nil) unless (subject(n)) raise(ArgumentError, "#{n} is not a subject.") else observing().delete(n) end return nil end
subject(n = nil). @description
Predicate. Verifies a Node is a subject.
@param n [Node]
Any instance.
@return [TrueClass, FalseClass]
True in the case the argument is an 'observing' element. False otherwise.
# File lib/node_observer_impl.rb, line 36 def subject(n = nil) return (observing().include?(n)) end
subject_changed
(subject = nil). @description
Adds an existing subject the changed Set.
@param subject [Node]
A subject.
@return [NilClass]
nil.
# File lib/node_observer_impl.rb, line 58 def subject_changed(subject = nil) receive_change(subject) return nil end
Protected Instance Methods
add_changed
(n = nil). @description
Adds changed a changed subject.
@param n [Node]
A changed subject.
@return [NilClass]
nil.
# File lib/node_observer_impl.rb, line 126 def add_changed(n = nil) unless (subject(n)) raise(ArgumentError, "#{n} is not a subject.") else changed().add(n) end return nil end
changed(). @description
Gets changed.
@return [Set]
changed's reference.
# File lib/node_observer_impl.rb, line 115 def changed() return @changed end
notify(n = nil). @description
Updates a subject's subscribers.
@param n [Node]
A changed subject.
@return [NilClass]
nil.
# File lib/node_observer_impl.rb, line 163 def notify(n = nil) Subscription.update(n) remove_changed(n) return nil end
observing(). @description
Gets 'observing'.
@return [Set]
observing's reference.
# File lib/node_observer_impl.rb, line 106 def observing() return @observing end
remove_changed
(n = nil). @description
Removes a changed subject. Calls after a Subscription update call.
@param n [Node]
A changed element. The element's subscribers were updated, so it is an unchanged subject.
@return [NilClass]
nil.
# File lib/node_observer_impl.rb, line 145 def remove_changed(n = nil) unless (changed_node(n)) raise(ArgumentError, "#{n} is not a changed subject.") else changed().delete(n) end return nil end
Private Instance Methods
changed=(s = nil). @description
Sets 'changed'.
@param s [Set]
An empty set.
@return [Set]
The argument.
# File lib/node_observer_impl.rb, line 191 def changed=(s = nil) @changed = s end
observing=(s = nil). @description
Sets observing.
@param s [Set]
An empty set.
@return [Set]
The argument.
# File lib/node_observer_impl.rb, line 180 def observing=(s = nil) @observing = s end
receive_change
(n = nil). @description
Receives a Node's state change.
@param n [Node]
An existing subject.
@return [NilClass]
nil.
# File lib/node_observer_impl.rb, line 202 def receive_change(n = nil) add_changed(n) notify(n) return nil end