Skip to content

Commit

Permalink
View[] will support specifying store [#22 state:resolved]
Browse files Browse the repository at this point in the history
  • Loading branch information
yrashk committed Apr 30, 2008
1 parent 599c3ba commit 318f468
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/strokedb/views/view.rb
Expand Up @@ -235,9 +235,12 @@ def self.[](view_name)
end

class << View
def [](name, nsurl = name.modulize.empty? ? Module.nsurl : name.modulize.constantize.nsurl) # FIXME: it is not nice
def [](*args) # FIXME: it is not nice
store = args.first.is_a?(Store) ? args.shift : StrokeDB.default_store
name = args[0]
nsurl = args[1] || (name.modulize.empty? ? Module.nsurl : name.modulize.constantize.nsurl)
uuid = ::Util.sha1_uuid("view:#{nsurl}##{name}")
StrokeDB.default_store.find(uuid)
store.find(uuid)
end

alias :original_new :new
Expand Down
3 changes: 3 additions & 0 deletions spec/lib/strokedb/views/view_spec.rb
Expand Up @@ -161,6 +161,7 @@ def view.map(uuid, doc)

it "should be findable with #[] syntax" do
View["SomeView"].should == @view
View[StrokeDB.default_store, "SomeView"].should == @view
end

end
Expand All @@ -178,7 +179,9 @@ def view.map(uuid, doc)
end
it "should be findable with #[] syntax" do
View["SomeView", "http://strokedb.com/"].should == @view
View[StrokeDB.default_store, "SomeView", "http://strokedb.com/"].should == @view
end

end


0 comments on commit 318f468

Please sign in to comment.