diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2012-05-18 11:46:07 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2012-05-18 11:46:07 +0200 |
commit | cb0ffa6cfd04dfae81bce57fbbe528f719d3efe5 (patch) | |
tree | 50ef5ce866751a81624eaa47dbe726d761702cb3 | |
parent | 3e01a17ec9ed22867b409ffedab20e160de90ff7 (diff) | |
download | edoors-ruby-cb0ffa6cfd04dfae81bce57fbbe528f719d3efe5.zip edoors-ruby-cb0ffa6cfd04dfae81bce57fbbe528f719d3efe5.tar.gz |
Spot->Iota
-rw-r--r-- | lib/iotas.rb | 2 | ||||
-rw-r--r-- | lib/iotas/door.rb | 2 | ||||
-rw-r--r-- | lib/iotas/iota.rb (renamed from lib/iotas/spot.rb) | 6 | ||||
-rw-r--r-- | lib/iotas/particle.rb | 4 | ||||
-rw-r--r-- | lib/iotas/room.rb | 34 | ||||
-rw-r--r-- | lib/iotas/spin.rb | 14 | ||||
-rw-r--r-- | spec/room_spec.rb | 4 | ||||
-rw-r--r-- | spec/spec_helper.rb | 4 | ||||
-rw-r--r-- | spec/spot_spec.rb | 12 |
9 files changed, 41 insertions, 41 deletions
diff --git a/lib/iotas.rb b/lib/iotas.rb index 24c021e..abafc7c 100644 --- a/lib/iotas.rb +++ b/lib/iotas.rb @@ -54,7 +54,7 @@ end # require 'json' require 'iotas/particle' -require 'iotas/spot' +require 'iotas/iota' require 'iotas/room' require 'iotas/spin' require 'iotas/door' diff --git a/lib/iotas/door.rb b/lib/iotas/door.rb index 8474b09..a5ffb97 100644 --- a/lib/iotas/door.rb +++ b/lib/iotas/door.rb @@ -21,7 +21,7 @@ # module Iotas # - class Door < Spot + class Door < Iota # def initialize n, p super n, p diff --git a/lib/iotas/spot.rb b/lib/iotas/iota.rb index aca0c2b..e26bf4f 100644 --- a/lib/iotas/spot.rb +++ b/lib/iotas/iota.rb @@ -21,7 +21,7 @@ # module Iotas # - class Spot + class Iota # def initialize n, p @name = n # unique in it's room @@ -29,8 +29,8 @@ module Iotas @viewer = nil # particle going through that position will be sent there readonly @path = ( @parent ? @parent.path+Iotas::PATH_SEP : '') + @name @spin = ( @parent ? @parent.spin : self ) - @parent.add_spot self if @parent - raise Iotas::Exception.new "Spot name #{name} is not valid" if @name.include? Iotas::PATH_SEP + @parent.add_iota self if @parent + raise Iotas::Exception.new "Iota name #{name} is not valid" if @name.include? Iotas::PATH_SEP end # attr_reader :name, :path, :spin diff --git a/lib/iotas/particle.rb b/lib/iotas/particle.rb index ffb141b..4141953 100644 --- a/lib/iotas/particle.rb +++ b/lib/iotas/particle.rb @@ -26,8 +26,8 @@ module Iotas # def initialize o={} @ts = Time.now # creation time - @src = nil # Spot where it's originated from - @dst = nil # Spot where it's heading to + @src = nil # Iota where it's originated from + @dst = nil # Iota where it's heading to @room = nil # Room path part of the current destination @door = nil # Door path part of the current destination @action = nil # action part of the current destination diff --git a/lib/iotas/room.rb b/lib/iotas/room.rb index 569c921..203b74c 100644 --- a/lib/iotas/room.rb +++ b/lib/iotas/room.rb @@ -21,11 +21,11 @@ # module Iotas # - class Room < Spot + class Room < Iota # def initialize n, p super n, p - @spots = {} + @iotas = {} @links = {} end # @@ -33,7 +33,7 @@ module Iotas { 'kls' => self.class.name, 'name' => @name, - 'spots' => @spots, + 'iotas' => @iotas, 'links' => @links }.to_json *a end @@ -41,8 +41,8 @@ module Iotas def self.json_create o raise Iotas::Exception.new "JSON #{o['kls']} != #{self.name}" if o['kls'] != self.name room = self.new o['name'], o['parent'] - o['spots'].each do |name,spot| - eval( spot['kls'] ).json_create(spot.merge!('parent'=>room)) + o['iotas'].each do |name,iota| + eval( iota['kls'] ).json_create(iota.merge!('parent'=>room)) end o['links'].each do |src,links| links.each do |link| @@ -52,35 +52,35 @@ module Iotas room end # - def add_spot s - raise Iotas::Exception.new "Spot #{s.name} already has #{s.parent.name} as parent" if not s.parent.nil? and s.parent!=self - raise Iotas::Exception.new "Spot #{s.name} already exists in #{path}" if @spots.has_key? s.name + def add_iota s + raise Iotas::Exception.new "Iota #{s.name} already has #{s.parent.name} as parent" if not s.parent.nil? and s.parent!=self + raise Iotas::Exception.new "Iota #{s.name} already exists in #{path}" if @iotas.has_key? s.name s.parent = self if s.parent.nil? - @spots[s.name]=s + @iotas[s.name]=s end # def add_link l - l.door = @spots[l.src] + l.door = @iotas[l.src] raise Iotas::Exception.new "Link source #{l.src} does not exist in #{path}" if l.door.nil? (@links[l.src] ||= [])<< l end # def start! puts " * start #{path}" if @spin.debug_routing - @spots.values.each do |spot| spot.start! end + @iotas.values.each do |iota| iota.start! end end # def stop! puts " * stop #{path}" if @spin.debug_routing - @spots.values.each do |spot| spot.stop! end + @iotas.values.each do |iota| iota.stop! end end # def search_down spath return self if spath==path return nil if (spath=~/^#{path}\/(\w+)\/?/)!=0 - if spot = @spots[$1] - return spot if spot.path==spath # needed as Door doesn't implement #search_down - return spot.search_down spath + if iota = @iotas[$1] + return iota if iota.path==spath # needed as Door doesn't implement #search_down + return iota.search_down spath end nil end @@ -114,14 +114,14 @@ module Iotas # def route_p p if p.room.nil? or p.room==path - if door = @spots[p.door] + if door = @iotas[p.door] p.dst_routed! door else p.error! Iotas::ERROR_ROUTE_RRWD end elsif (p.room=~/^#{path}\/(.*)/)==0 room, *more = $1.split Iotas::PATH_SEP - if child=@spots[room] + if child=@iotas[room] child.route_p p else p.error! Iotas::ERROR_ROUTE_DDWR diff --git a/lib/iotas/spin.rb b/lib/iotas/spin.rb index 03c0141..4c8e238 100644 --- a/lib/iotas/spin.rb +++ b/lib/iotas/spin.rb @@ -37,9 +37,9 @@ module Iotas @debug_routing = o[:debug_routing]||o['debug_routing']||false # if not o.empty? - o['spots'].each do |name,spot| - Iotas::Room.json_create(spot.merge!('parent'=>self)) - end if o['spots'] + o['iotas'].each do |name,iota| + Iotas::Room.json_create(iota.merge!('parent'=>self)) + end if o['iotas'] o['app_fifo'].each do |particle| @app_fifo << Iotas::Particle.json_create(particle.merge!('spin'=>self)) end if o['app_fifo'] @@ -57,7 +57,7 @@ module Iotas 'timestamp' => Time.now, 'name' => @name, 'hibernation' => @hibernation, - 'spots' => @spots, + 'iotas' => @iotas, 'sys_fifo' => @sys_fifo, 'app_fifo' => @app_fifo, 'debug_errors' => @debug_errors, @@ -71,7 +71,7 @@ module Iotas end # def clear! - @spots.clear + @iotas.clear @pool.clear @sys_fifo.clear @app_fifo.clear @@ -113,7 +113,7 @@ module Iotas end # def spin! - @spots.values.each do |spot| spot.start! end unless @hibernation + @iotas.values.each do |iota| iota.start! end unless @hibernation @run = true @hibernation = false while @run and (@sys_fifo.length>0 or @app_fifo.length>0) @@ -127,7 +127,7 @@ module Iotas break end end - @spots.values.each do |spot| spot.stop! end unless @hibernation + @iotas.values.each do |iota| iota.stop! end unless @hibernation end # def stop! diff --git a/spec/room_spec.rb b/spec/room_spec.rb index 06811a5..1d394ac 100644 --- a/spec/room_spec.rb +++ b/spec/room_spec.rb @@ -14,11 +14,11 @@ describe Iotas::Room do @spin.clear! end # - it "add_spot and add_link correctly" do + it "add_iota and add_link correctly" do r0 = Iotas::Room.new 'room0', @spin d0 = Iotas::Door.new 'door0', r0 lambda { Iotas::Door.new('door0', r0) }.should raise_error(Iotas::Exception) - lambda { r0.add_spot Iotas::Door.new('door1', r0) }.should raise_error(Iotas::Exception) + lambda { r0.add_iota Iotas::Door.new('door1', r0) }.should raise_error(Iotas::Exception) r0.add_link Iotas::Link.new 'door0', 'somewhere' lambda { r0.add_link(Iotas::Link.new('nowhere', 'somewhere')) }.should raise_error(Iotas::Exception) end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index e3e0aa1..5a549c5 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -11,7 +11,7 @@ end # require 'iotas' # -class Fake < Iotas::Spot +class Fake < Iotas::Iota attr_reader :p, :sp, :start, :stop def process_p p @p = p @@ -25,7 +25,7 @@ class Fake < Iotas::Spot def send_sys_p p @sp = p end - def add_spot p + def add_iota p end def start! @start=true diff --git a/spec/spot_spec.rb b/spec/spot_spec.rb index eb64f33..1ed2b03 100644 --- a/spec/spot_spec.rb +++ b/spec/spot_spec.rb @@ -4,11 +4,11 @@ require 'spec_helper' # -describe Iotas::Spot do +describe Iotas::Iota do # it "path construction" do - class S<Iotas::Spot - def add_spot s + class S<Iotas::Iota + def add_iota s end end s0 = S.new 'top', nil @@ -16,9 +16,9 @@ describe Iotas::Spot do s2 = S.new 'room1', s1 s3 = S.new 'door', s2 s3.path.should eql 'top/room0/room1/door' - lambda { Iotas::Spot.new('do/or0', nil) }.should raise_error(Iotas::Exception) - lambda { Iotas::Spot.new('/door0', nil) }.should raise_error(Iotas::Exception) - lambda { Iotas::Spot.new('door0/', nil) }.should raise_error(Iotas::Exception) + lambda { Iotas::Iota.new('do/or0', nil) }.should raise_error(Iotas::Exception) + lambda { Iotas::Iota.new('/door0', nil) }.should raise_error(Iotas::Exception) + lambda { Iotas::Iota.new('door0/', nil) }.should raise_error(Iotas::Exception) end # end |