summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2012-05-10 17:47:55 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2012-05-10 17:47:55 +0200
commit8e2408c735e659741542d66cd032d4c3405cd5e0 (patch)
treec40e4dad0cf8d221c890b315e2c25c595c7be3b3
parentc596b64931fec2db2c1a198b7124431b04fc673d (diff)
downloadedoors-ruby-8e2408c735e659741542d66cd032d4c3405cd5e0.zip
edoors-ruby-8e2408c735e659741542d66cd032d4c3405cd5e0.tar.gz
Room#resolve -> Room#search_down
-rw-r--r--lib/evendoors/particle.rb4
-rw-r--r--lib/evendoors/room.rb17
-rw-r--r--spec/room_spec.rb12
3 files changed, 17 insertions, 16 deletions
diff --git a/lib/evendoors/particle.rb b/lib/evendoors/particle.rb
index f532be1..f4c4ab7 100644
--- a/lib/evendoors/particle.rb
+++ b/lib/evendoors/particle.rb
@@ -26,8 +26,8 @@ module EvenDoors
@door = o['door']
@action = o['action']
@payload = o['payload']||{}
- @src = EvenDoors::Spin.spin.resolve o['src'] if o['src']
- @dst = EvenDoors::Spin.spin.resolve o['dst'] if o['dst']
+ @src = EvenDoors::Spin.spin.search_down o['src'] if o['src']
+ @dst = EvenDoors::Spin.spin.search_down o['dst'] if o['dst']
o['dsts'].each do |dst| add_dsts dst end if o['dsts']
set_link_fields *o['link_fields'] if o['link_fields']
o['merged'].each do |merged| merge! Particle.json_create(merged) end if o['merged']
diff --git a/lib/evendoors/room.rb b/lib/evendoors/room.rb
index eaa8ace..90b824c 100644
--- a/lib/evendoors/room.rb
+++ b/lib/evendoors/room.rb
@@ -42,17 +42,14 @@ module EvenDoors
@spin = ( @parent.nil? ? self : @parent.spin )
end
#
- def resolve search
- return self if search==path
- if (search=~/^#{path}\/(\w+)\/?/)==0
- if spot = @spots[$1]
- return spot if spot.path==search # needed as Door doesn't implement #resolve
- return spot.resolve search
- else
- nil
- 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
end
- (@parent ? @parent.resolve(search) : nil )
+ nil
end
#
def try_links p
diff --git a/spec/room_spec.rb b/spec/room_spec.rb
index 379de32..badea97 100644
--- a/spec/room_spec.rb
+++ b/spec/room_spec.rb
@@ -30,7 +30,7 @@ describe EvenDoors::Room do
d0.stop.should be_true
end
#
- it "parent, spin and resolve should be ok" do
+ it "parent, spin and search_down should be ok" do
EvenDoors::Spin.spin = nil
s = EvenDoors::Spin.new 'dom0'
r0 = EvenDoors::Room.new 'r0', s
@@ -45,9 +45,13 @@ describe EvenDoors::Room do
r1.spin.should be s
r2.spin.should be s
r3.spin.should be s
- r2.resolve('dom0/r0/r1/r2').should be r2
- r3.resolve('dom0/r0/r1/r2').should be r2
- r1.resolve('dom0/r0/r1/r2').should be r2
+ s.search_down('dom0/r0/r1/r2').should be r2
+ r0.search_down('dom0/r0/r1/r2').should be r2
+ r1.search_down('dom0/r0/r1/r2').should be r2
+ r2.search_down('dom0/r0/r1/r2').should be r2
+ r1.search_down('dom0/r0/r1/r9').should be nil
+ r3.search_down('dom0/r0/r1/r2').should be nil
+ r4.search_down('dom0/r0/r1/r2').should be nil
end
#
it "route error: no source" do