From bee11419fe984734f414a78e87b4e214256b13c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Thu, 10 May 2012 23:18:58 +0200 Subject: Spin: implement #to_json and #self.json_create --- lib/evendoors/spin.rb | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/lib/evendoors/spin.rb b/lib/evendoors/spin.rb index 5608f46..882e563 100644 --- a/lib/evendoors/spin.rb +++ b/lib/evendoors/spin.rb @@ -19,6 +19,26 @@ module EvenDoors # attr_accessor :spin, :run, :debug_routing, :debug_errors # + def to_json *a + { + 'sys_fifo' => @sys_fifo, + 'app_fifo' => @app_fifo, + 'debug_routing' => @debug_routing, + 'debug_errors' => @debug_errors + }.to_json(*a) + end + # + def static_json_create o + @debug_routing = o['debug_routing'] + @debug_errors = o['debug_errors'] + o['app_fifo'].each do |particle| + @app_fifo << EvenDoors::Particle.json_create(particle) + end + o['sys_fifo'].each do |particle| + @sys_fifo << EvenDoors::Particle.json_create(particle) + end + end + # def release_p p # hope there is no circular loop while p2=p.merged_shift @@ -75,6 +95,25 @@ module EvenDoors self.class.debug_routing = args[:debug_routing] || false end # + def to_json *a + { + 'kls' => self.class.name, + 'name' => @name, + 'spots' => @spots, + 'static' => EvenDoors::Spin + }.to_json(*a) + end + # + def self.json_create o + raise EvenDoors::Exception.new "JSON #{o['kls']} != #{self.name}" if o['kls'] != self.name + spin = self.new(o['name']) + o['spots'].each do |name,spot| + spin.add_spot EvenDoors::Room.json_create spot + end + EvenDoors::Spin.static_json_create o['static'] + spin + end + # def spin! @spots.values.each do |spot| spot.start! end self.class.run = true -- cgit v1.1-2-g2b99