diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2012-05-10 17:34:39 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2012-05-10 17:34:39 +0200 |
commit | bed8e682e80a810c66f309faf7865872aadc85cc (patch) | |
tree | 57509b1a08d9438c12b88c36aef9a90abca72311 | |
parent | d916c197fd06eb5f818e2bd75d5d1312c4758975 (diff) | |
download | edoors-ruby-bed8e682e80a810c66f309faf7865872aadc85cc.zip edoors-ruby-bed8e682e80a810c66f309faf7865872aadc85cc.tar.gz |
Spin register itself in its class, aka singleton
-rw-r--r-- | lib/evendoors/spin.rb | 5 | ||||
-rw-r--r-- | spec/room_spec.rb | 2 | ||||
-rw-r--r-- | spec/spin_spec.rb | 7 |
3 files changed, 13 insertions, 1 deletions
diff --git a/lib/evendoors/spin.rb b/lib/evendoors/spin.rb index 31904e8..6b88a55 100644 --- a/lib/evendoors/spin.rb +++ b/lib/evendoors/spin.rb @@ -10,13 +10,14 @@ module EvenDoors @sys_fifo = [] # system particles fifo list @app_fifo = [] # application particles fifo list # + @spin = nil @run = false @debug_routing = false @debug_errors = false # class << self # - attr_accessor :run, :debug_routing, :debug_errors + attr_accessor :spin, :run, :debug_routing, :debug_errors # def release_p p # hope there is no circular loop @@ -66,6 +67,8 @@ module EvenDoors # def initialize n, args={} super n, nil + raise EvenDoors::Exception.new "do not try to initialize more than one spin" if not self.class.spin.nil? + self.class.spin = self self.class.debug_errors = args[:debug_errors] || false self.class.debug_routing = args[:debug_routing] || false end diff --git a/spec/room_spec.rb b/spec/room_spec.rb index b794900..a683035 100644 --- a/spec/room_spec.rb +++ b/spec/room_spec.rb @@ -30,6 +30,7 @@ describe EvenDoors::Room do end # it "parent, spin and resolve should be ok" do + EvenDoors::Spin.spin = nil s = EvenDoors::Spin.new 'dom0' r0 = EvenDoors::Room.new 'r0', s r1 = EvenDoors::Room.new 'r1', r0 @@ -238,6 +239,7 @@ describe EvenDoors::Room do # it "SYS_ACT_ADD_LINK" do EvenDoors::Spin.clear! + EvenDoors::Spin.spin = nil spin = EvenDoors::Spin.new 'dom0' # needed to be able to route to door room0 = EvenDoors::Room.new 'room0', spin door0 = EvenDoors::Door.new 'door0', room0 diff --git a/spec/spin_spec.rb b/spec/spin_spec.rb index 6fd8ccd..97ba7b2 100644 --- a/spec/spin_spec.rb +++ b/spec/spin_spec.rb @@ -64,6 +64,7 @@ describe EvenDoors::Spin do EvenDoors::Spin.debug_routing = false EvenDoors::Spin.debug_routing.should be false # + EvenDoors::Spin.spin = nil EvenDoors::Spin.debug_errors.should be false spin = EvenDoors::Spin.new 'dom0', :debug_errors=>true EvenDoors::Spin.debug_errors.should be true @@ -72,6 +73,12 @@ describe EvenDoors::Spin do EvenDoors::Spin.debug_errors.should be false end # + it "only 1 Spin instance" do + EvenDoors::Spin.spin = nil + spin = EvenDoors::Spin.new 'dom0', :debug_routing=>true + lambda { EvenDoors::Spin.new('dom1') }.should raise_error(EvenDoors::Exception) + end + # end # #EOF |