Class: Andromeda::Spot
- Inherits:
-
Impl::ConnectorBase
- Object
- Impl::ConnectorBase
- Andromeda::Spot
- Includes:
- Impl::To_S
- Defined in:
- lib/andromeda/spot.rb
Overview
A spot is a reachable destination to which data may be sent for processing. It encapsulates addressing the processing logic of a Plan into a separate, immutable Object that may be passed around freely.
It is somewhat similiar/a mixture of notions such as actor address, RPC endpoint, and stack frame in other frameworks
You MUST not inherit from this class
Instance Attribute Summary collapse
-
#here ⇒ Plan?
readonly
Plan of calling spot if any, nil otherwise.
-
#name ⇒ Symbol
readonly
Name of spot attribute in plan that corresponds to this spot.
-
#plan ⇒ Plan
readonly
Plan to which this spot will deliver data events.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Spots compare attribute-wise and do not accept subclasses.
- #>>(target) ⇒ Object
-
#call_local(key, val) ⇒ Any
Call the spot method associated with this spot with the provided key and val.
- #clone_to_copy? ⇒ Boolean
- #cloneable? ⇒ Boolean
-
#dest ⇒ Spot
Plan.public_spot(dest_name) if that exists, plan.dest otherwise.
-
#dest_name ⇒ Symbol?
Spot’s destination name, or nil for plan.dest, returned by >>.
-
#entry ⇒ self
For compatibility with plan’s API.
- #hash ⇒ Object
- #identical_copy ⇒ Object
-
#initialize(plan, name, here, dest = nil) ⇒ Spot
constructor
A new instance of Spot.
-
#intern(new_calling_plan) ⇒ Spot
This spot or a modified copy of it such that here == new_calling_plan holds.
-
#post_to(track, data, tags_in = {}) ⇒ self
Post data with the associated tags_in to this’s spot’s plan’s method spot with name name and hint that the caller requested the spot activation to be executed on track tack.
- #to_short_s ⇒ Object
-
#via(spot_name) ⇒ Spot
A fresh copy of self for which dest_name == spot_name holds.
Methods included from Impl::To_S
Methods inherited from Impl::ConnectorBase
Constructor Details
#initialize(plan, name, here, dest = nil) ⇒ Spot
Returns a new instance of Spot.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/andromeda/spot.rb', line 31 def initialize(plan, name, here, dest = nil) raise ArgumentError, "#{plan} is not a Plan" unless plan.is_a? Plan raise ArgumentError, "#{name} is not a Symbol" unless name.is_a? Symbol unless plan.meth_spot_name?(name) raise ArgumentError, "#{name} is not a known method spot name of #{plan}" end unless dest.nil? || dest.is_a?(Symbol) raise ArgumentError, "#{dest} is neither nil nor a Symbol" end if !here || here.is_a?(Plan) @plan = plan @name = name @here = here @dest = dest else raise ArgumentError, "#{here} is neither nil nor a Plan" end end |
Instance Attribute Details
#here ⇒ Plan? (readonly)
Returns Plan of calling spot if any, nil otherwise.
22 23 24 |
# File 'lib/andromeda/spot.rb', line 22 def here @here end |
#name ⇒ Symbol (readonly)
Returns Name of spot attribute in plan that corresponds to this spot.
19 20 21 |
# File 'lib/andromeda/spot.rb', line 19 def name @name end |
#plan ⇒ Plan (readonly)
Returns Plan to which this spot will deliver data events.
16 17 18 |
# File 'lib/andromeda/spot.rb', line 16 def plan @plan end |
Instance Method Details
#==(other) ⇒ Object
Spots compare attribute-wise and do not accept subclasses
57 58 59 60 61 |
# File 'lib/andromeda/spot.rb', line 57 def ==(other) return true if self.equal? other return false unless other.class.equal? Spot name.eq(other.name) && plan.eq(other.plan) && here.eq(other.here) && dest.eq(other.dest) end |
#>>(target) ⇒ Object
115 116 117 118 119 120 121 122 |
# File 'lib/andromeda/spot.rb', line 115 def >>(target) return (plan >> target) unless dest_name unless plan.attr_spot_name?(dest_name) raise ArgumentError, "#{dest_name} is not an attr_spot_name" end plan.send :"#{dest_name}=", target.entry plan.public_spot(dest_name) end |
#call_local(key, val) ⇒ Any
Call the spot method associated with this spot with the provided key and val
Precondition is that here == plan, i.e. the caller already executes in the scope of this spot’s plan
101 102 103 |
# File 'lib/andromeda/spot.rb', line 101 def call_local(key, val) plan.call_local name, key, val end |
#clone_to_copy? ⇒ Boolean
51 |
# File 'lib/andromeda/spot.rb', line 51 def clone_to_copy? ; false end |
#cloneable? ⇒ Boolean
50 |
# File 'lib/andromeda/spot.rb', line 50 def cloneable? ; true end |
#dest ⇒ Spot
Returns plan.public_spot(dest_name) if that exists, plan.dest otherwise.
109 110 111 112 113 |
# File 'lib/andromeda/spot.rb', line 109 def dest if dest_name then plan.public_spot(dest_name) else plan.dest end end |
#dest_name ⇒ Symbol?
Returns Spot’s destination name, or nil for plan.dest, returned by >>.
25 |
# File 'lib/andromeda/spot.rb', line 25 def dest_name ; @dest end |
#entry ⇒ self
Returns for compatibility with plan’s API.
106 |
# File 'lib/andromeda/spot.rb', line 106 def entry ; self end |
#hash ⇒ Object
63 |
# File 'lib/andromeda/spot.rb', line 63 def hash ; plan.hash ^ name.hash ^ here.hash ^ dest.hash end |
#identical_copy ⇒ Object
52 |
# File 'lib/andromeda/spot.rb', line 52 def identical_copy ; self end |
#intern(new_calling_plan) ⇒ Spot
Returns this spot or a modified copy of it such that here == new_calling_plan holds.
125 126 127 128 129 |
# File 'lib/andromeda/spot.rb', line 125 def intern(new_calling_plan) if here.equal? new_calling_plan then self else Spot.new plan, name, new_calling_plan, dest_name end end |
#post_to(track, data, tags_in = {}) ⇒ self
Post data with the associated tags_in to this’s spot’s plan’s method spot with name name and hint that the caller requested the spot activation to be executed on track tack
83 84 85 86 87 |
# File 'lib/andromeda/spot.rb', line 83 def post_to(track, data, = {}) = (here..identical_copy.update() rescue ) if here plan.post_data self, track, data, self end |
#to_short_s ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/andromeda/spot.rb', line 65 def to_short_s dest_ = dest_name dest_ = if dest_ then " dest=:#{dest_name}" else '' end here_ = here if here_ then " plan=#{plan} name=:#{name} here=#{here_}#{dest_}" else " plan=#{plan} name=:#{name}#{dest_}" end end |