public
Description: StrokeDB is an embeddable distributed document database written in Ruby
Homepage: http://strokedb.com/
Clone URL: git://github.com/yrashk/strokedb.git
View#[] syntax has been implemented [#13 responsible:yrashk state:resolved]
yrashk (author)
Tue Apr 29 00:06:51 -0700 2008
commit  3fbc394d5cd33891b157318e7984ec3d7b8dff7e
tree    b38e88e724742ee7b4cc0c8427fe5ee7898cd244
parent  cd9a00e70e4a197c121fef6fc62361e948fdd037
...
234
235
236
237
238
 
 
 
239
240
241
...
259
260
261
262
 
263
264
265
...
234
235
236
 
 
237
238
239
240
241
242
...
260
261
262
 
263
264
265
266
0
@@ -234,8 +234,9 @@ module StrokeDB
0
   end
0
   
0
   class << View
0
-    def [](name)
0
-      # TODO: find viewdoc by name
0
+    def [](name, nsurl = Meta.default_nsurl)  # FIXME: Meta seems to be a bad place for default_nsurl now
0
+      uuid = ::Util.sha1_uuid("view:#{nsurl}##{name}") 
0
+      StrokeDB.default_store.find(uuid)
0
     end
0
 
0
     alias :original_new :new
0
@@ -259,7 +260,7 @@ module StrokeDB
0
         raise ArgumentError, "View name must be specified!"
0
       end
0
       
0
-      nsurl = options['nsurl'] ||= Meta.default_nsurl # FIXME: Meta seems to be a bad palce for default_nsurl now
0
+      nsurl = options['nsurl'] ||= Meta.default_nsurl # FIXME: Meta seems to be a bad place for default_nsurl now
0
       
0
       options['uuid'] = ::Util.sha1_uuid("view:#{nsurl}##{name}") 
0
       
...
112
113
114
115
116
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
112
113
114
 
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
0
@@ -112,4 +112,26 @@ describe View, "with block defined and saved" do
0
     @view.send(:storage).object_id.should == storage_id
0
   end
0
   
0
-end
0
\ No newline at end of file
0
+  it "should be findable with #[] syntax" do
0
+    View["SomeView"].should == @view
0
+  end
0
+  
0
+end
0
+
0
+
0
+describe View, "with nsurl and block defined and saved" do
0
+  
0
+  before(:each) do
0
+    setup_default_store
0
+    @view = View.define!("SomeView", :nsurl => "http://strokedb.com/") do |view|
0
+      def view.map(uuid, doc)
0
+        [[doc,doc]]
0
+      end
0
+    end
0
+  end
0
+  it "should be findable with #[] syntax" do
0
+    View["SomeView", "http://strokedb.com/"].should == @view
0
+  end
0
+  
0
+end
0
+

Comments