class NodeSubscription
NodeSubscription
. @class_description
A NodeSubscription library implementation.
@attr instance [NodeSubscription]
A singleton instance.
@attr feeds [Set]
All subscription feeds. Its elements are hashes. The keys are Node references, and their values are Sets containing corresponding subscribers.
NodeSubscription
. @class_description
A NodeSubscription library implementation.
@attr instance [NodeSubscription]
A singleton instance.
@attr feeds [Set]
All subscription feeds. Its elements are hashes. The keys are Node references, and their values are Sets containing corresponding subscribers.
Constants
- VERSION
Public Class Methods
self.instance(). @description
Lazily initializes a singleton instance, or gets the singleton instance.
@return [NodeSubscription]
The singleton.
# File lib/node_subscription_impl.rb, line 23 def self.instance() if (@instance.nil?()) then self.instance = new() end return @instance end
Private Class Methods
self.instance=(s = nil). @description
Sets the singleton instance.
@param s [NodeSubscription]
The singleton NodeSubscription instance.
@return [NodeSubscription]
The argument.
# File lib/node_subscription_impl.rb, line 200 def self.instance=(s = nil) @instance = s end
initialize(). @description
Initializes the singleton instance.
# File lib/node_subscription_impl.rb, line 189 def initialize() self.feeds = Set[] end
Public Instance Methods
add_publisher
(p = nil). @description
Adds a Node publisher.
@param p [Node]
Any instance.
@return [NilClass]
nil.
# File lib/node_subscription_impl.rb, line 78 def add_publisher(p = nil) publishable_set = NodeSubscription.publishable() p_class = p.class() if (publisher(p)) raise(ArgumentError, "#{p} was added previously.") elsif (!publishable_set.include?(p_class)) raise(ArgumentError, "#{p} is not a publishable object.") else feed_hash = {} feed_hash[p] = Set[] feeds().add(feed_hash) end return nil end
add_subscriber
(p = nil, s = nil). @description
Adds a subscriber a publisher's Set.
@param p [Node]
A publisher.
@param s [.]
Any subscribable instance.
@return [NilClass]
nil.
# File lib/node_subscription_impl.rb, line 106 def add_subscriber(p = nil, s = nil) if ((!publisher(p)) || (feed(p).include?(s)) || (!NodeSubscription.s_instance(s))) raise(ArgumentError, "#{p} never registered as a publisher, or #{s} was previously subscribed.") else p_feed = feed(p) p_feed.add(s) end return nil end
publisher(p = nil). @description
Predicate. Verifies a Node is a feed publisher.
@param p [Node]
Any instance.
@return [TrueClass, FalseClass]
True in the case p is a feeds key. False otherwise.
# File lib/node_subscription_impl.rb, line 35 def publisher(p = nil) feeds().to_a().each { |feed| if (feed.key?(p)) then return true end } return false end
update_subscribers
(p = nil). @description
Updates a publisher's subscribers.
@param p [Node]
A changed subject.
@return [NilClass]
nil.
# File lib/node_subscription_impl.rb, line 51 def update_subscribers(p = nil) unless (publisher(p)) raise(ArgumentError, "#{p} is not a publisher.") else p_feed = feed(p) p_feed.each { |subscriber| factory = kind_factory(subscriber) singleton = factory.instance() singleton.diagram_update(p) } end return nil end
Protected Instance Methods
feed(p = nil). @description
Gets a publisher's feed.
@param p [Node]
A publisher.
@return [Set]
p's feed.
@raise [ArgumentError]
In the case p is not a feeds element hash key.
# File lib/node_subscription_impl.rb, line 141 def feed(p = nil) if (publisher(p)) feeds().to_a().each { |feed| if (feed.key?(p)) then return feed[p] end } else raise(ArgumentError, "#{p} was never added.") end end
feeds(). @description
Gets feeds.
@return [Set]
feeds' reference.
# File lib/node_subscription_impl.rb, line 128 def feeds() return @feeds end
Private Instance Methods
feeds=(s = nil). @description
Sets feeds.
@param s [Set]
An empty Set.
@return [Set]
The argument.
# File lib/node_subscription_impl.rb, line 164 def feeds=(s = nil) @feeds = s end
kind_factory
(s = nil). @description
Gets a subscriber's factory.
@param s [.]
A feed subscriber.
@return [.]
A factory identifier.
# File lib/node_subscription_impl.rb, line 175 def kind_factory(s = nil) case when s.instance_of?(NodeDiagram) return DiagramFactory else raise(ArgumentError, "#{s}\'s factory is nonexistent.") end end