summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/evendoors/particle.rb77
1 files changed, 41 insertions, 36 deletions
diff --git a/lib/evendoors/particle.rb b/lib/evendoors/particle.rb
index ef02b53..ea84f8a 100644
--- a/lib/evendoors/particle.rb
+++ b/lib/evendoors/particle.rb
@@ -8,21 +8,22 @@ module EvenDoors
#
def initialize
@ts = Time.now # creation time
- @src = nil # Spot.path where it's originated from
+ @src = nil # Spot where it's originated from
+ @dst = nil # Spot where it's heading to
@room = nil # Room path part of the current destination
- @door = nil # Door where it's currently heading to
- @action = nil # action to perform on the Door
- @dsts = [] # fifo of Spot.path where to travel to
- @link_fields = [] # the fields used to generate the link value
+ @door = nil # Door path part of the current destination
+ @action = nil # action part of the current destination
@link_value = nil # the value computed with the link_fields values extracted from the payload
- # used for pearing in Door and linking in routing process
+ # used for pearing Particles in Boards and linking in routing process
+ @dsts = [] # fifo of path?action strings where to travel to
+ @link_fields = [] # the fields used to generate the link value
@payload = {} # the actual data carried by this particle
@merged = [] # list of merged particles
end
#
def reset!
@ts = Time.now
- @src = @room = @door = @action = @link_value = nil
+ @src = @dst = @room = @door = @action = @link_value = nil
@dsts.clear
@link_fields.clear
@payload.clear
@@ -30,71 +31,75 @@ module EvenDoors
end
#
attr_accessor :src
- attr_reader :ts, :room, :door, :action, :link_value, :payload
+ attr_reader :ts, :dst, :room, :door, :action, :link_value, :payload
#
# routing
#
- def dst
+ def next_dst
@dsts[0]
end
#
+ def clear_dsts!
+ @dsts.clear
+ end
+ #
+ def add_dsts paths
+ paths.split(EvenDoors::LINK_SEP).each do |path|
+ @dsts << path.sub(/^\/+/,'').sub(/\/+$/,'').gsub(/\/{2,}/,'/')
+ end
+ end
+ #
+ def set_dst! a, d=nil
+ @dst = @room = @door = @action = nil
+ clear_dsts!
+ @dsts << ( d ? d.sub(/^\/+/,'').sub(/\/+$/,'').gsub(/\/{2,}/,'/') : '' )+EvenDoors::ACT_SEP+a.to_str
+ end
+ #
def split_dst!
- p, @action = @dsts[0].split EvenDoors::ACT_SEP
+ @dst = nil
+ p, @action = next_dst.split EvenDoors::ACT_SEP
i = p.rindex EvenDoors::PATH_SEP
if i.nil?
@room = nil
- door_name = p
+ @door = p
else
@room = p[0..i-1]
- door_name = p[i+1..-1]
+ @door = p[i+1..-1]
end
- door_name
+ @door = nil if @door.empty?
end
#
- def dst_done! door
+ def dst_routed! dst
+ @dst = dst
@dsts.shift
- @door = door
end
#
def error! e
@action = EvenDoors::ACT_ERROR
- @door = @src
+ @dst = @src
@payload[EvenDoors::ERROR_FIELD]=e
end
#
- def clear_dsts!
- @dsts.clear
- end
- #
- def add_dsts paths
- paths.split(EvenDoors::LINK_SEP).each do |path|
- @dsts << path
- end
- end
+ # data manipulation
#
- def set_dst a, l=nil
- @room = nil
- @door = nil
- @action = nil
- clear_dsts!
- @dsts << ( l ? l.to_str : '' )+EvenDoors::ACT_SEP+a.to_str
+ def []= k, v
+ @payload[k]=v
+ compute_link_value! if @link_fields.include? k
end
#
- # data manipulation
- #
def set_data k, v
@payload[k] = v
compute_link_value! if @link_fields.include? k
end
#
- def get_data k
+ def [] k
@payload[k]
end
- alias :data :get_data
#
- def data k
+ def get_data k
@payload[k]
end
+ alias :data :get_data
#
def clone_data p
@payload = p.payload.clone