couch-quilt 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/couch-quilt.gemspec +1 -1
- data/lib/couchquilt/fs.rb +14 -6
- data/lib/couchquilt/version.rb +1 -1
- data/spec/couchquilt_spec.rb +62 -23
- metadata +1 -1
data/couch-quilt.gemspec
CHANGED
data/lib/couchquilt/fs.rb
CHANGED
@@ -14,7 +14,9 @@ module Couchquilt
|
|
14
14
|
|
15
15
|
list case named_path(path)
|
16
16
|
when :root
|
17
|
-
@couch.get("_all_dbs")
|
17
|
+
["_uuids"] + @couch.get("_all_dbs")
|
18
|
+
when :uuids
|
19
|
+
["0i.js"]
|
18
20
|
when :database
|
19
21
|
["_design"] +
|
20
22
|
# database meta data
|
@@ -59,7 +61,7 @@ module Couchquilt
|
|
59
61
|
doc = get_view_result_part(database, id, parts)
|
60
62
|
# arrays and hashes are mapped into directories
|
61
63
|
doc.is_a?(Hash) || doc.is_a?(Array)
|
62
|
-
when :database_info, :show_function_result, :list_function_result
|
64
|
+
when :database_info, :show_function_result, :list_function_result, :uuid
|
63
65
|
false
|
64
66
|
when nil
|
65
67
|
# look into document
|
@@ -78,7 +80,7 @@ module Couchquilt
|
|
78
80
|
database, id, *parts = extract_parts(path)
|
79
81
|
|
80
82
|
case named_path(path)
|
81
|
-
when :database_info, :show_function_result, :list_function_result
|
83
|
+
when :database_info, :show_function_result, :list_function_result, :uuid
|
82
84
|
true
|
83
85
|
when :view_function_result
|
84
86
|
# Every javascript or HTML is file, based on extension
|
@@ -108,6 +110,8 @@ module Couchquilt
|
|
108
110
|
@couch.get(remove_extname(File.join(database, id, "_list", *parts)))
|
109
111
|
when :view_function_result
|
110
112
|
get_view_result_part(database, id, parts)
|
113
|
+
when :uuid
|
114
|
+
get_document_part(database, id, ["uuids"])
|
111
115
|
else
|
112
116
|
get_document_part(database, id, parts)
|
113
117
|
end
|
@@ -121,7 +125,7 @@ module Couchquilt
|
|
121
125
|
case named_path(path)
|
122
126
|
when :switch_delete_database, :switch_delete_document
|
123
127
|
true
|
124
|
-
when :database_info, :show_function_result, :list_function_result, :view_function_result
|
128
|
+
when :database_info, :show_function_result, :list_function_result, :view_function_result, :uuid
|
125
129
|
false
|
126
130
|
else
|
127
131
|
File.basename(path) !~ /\A_/ && File.extname(path) == ".js"
|
@@ -144,7 +148,7 @@ module Couchquilt
|
|
144
148
|
return false if File.basename(path) =~ /\A_/
|
145
149
|
|
146
150
|
case named_path(path)
|
147
|
-
when :database_info, :show_function_result, :list_function_result, :view_function_result
|
151
|
+
when :database_info, :show_function_result, :list_function_result, :view_function_result, :uuid
|
148
152
|
false
|
149
153
|
else
|
150
154
|
true
|
@@ -255,6 +259,10 @@ module Couchquilt
|
|
255
259
|
if database.nil?
|
256
260
|
# /
|
257
261
|
:root
|
262
|
+
elsif database == "_uuids" && id.nil?
|
263
|
+
:uuids
|
264
|
+
elsif database == "_uuids"
|
265
|
+
:uuid
|
258
266
|
elsif id == "_delete"
|
259
267
|
:switch_delete_database
|
260
268
|
elsif parts.size == 1 && parts.first == "_delete"
|
@@ -385,7 +393,7 @@ module Couchquilt
|
|
385
393
|
# Appends extname, that is: builds a filename from key and value.
|
386
394
|
# Note: values are casted by extension.
|
387
395
|
def append_extname(key, value)
|
388
|
-
basename = key.is_a?(Integer) ? "
|
396
|
+
basename = key.is_a?(Integer) ? "%di" % key : key
|
389
397
|
|
390
398
|
case value
|
391
399
|
when Float
|
data/lib/couchquilt/version.rb
CHANGED
data/spec/couchquilt_spec.rb
CHANGED
@@ -52,6 +52,9 @@ describe "Quilt" do
|
|
52
52
|
it "contents should list databases" do
|
53
53
|
@quilt.contents("/").should include(TESTDB)
|
54
54
|
end
|
55
|
+
it "contents should include _uuids" do
|
56
|
+
@quilt.contents("/").should include("_uuids")
|
57
|
+
end
|
55
58
|
it "can_mkdir? should return false" do
|
56
59
|
@quilt.can_mkdir?("/").should be_false
|
57
60
|
end
|
@@ -300,7 +303,7 @@ describe "Quilt" do
|
|
300
303
|
@quilt.file?("/#{TESTDB}/document_id/array").should be_false
|
301
304
|
end
|
302
305
|
it "contents should list array content" do
|
303
|
-
@quilt.contents("/#{TESTDB}/document_id/array").should == ["
|
306
|
+
@quilt.contents("/#{TESTDB}/document_id/array").should == ["0i.js"]
|
304
307
|
end
|
305
308
|
it "can_mkdir? should return false" do
|
306
309
|
@quilt.can_mkdir?("/#{TESTDB}/document_id/array").should be_false
|
@@ -605,7 +608,7 @@ describe "Quilt" do
|
|
605
608
|
@quilt.file?("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows").should be_false
|
606
609
|
end
|
607
610
|
it "contents should list view rows" do
|
608
|
-
@quilt.contents("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows").should == ["
|
611
|
+
@quilt.contents("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows").should == ["0i"]
|
609
612
|
end
|
610
613
|
it "can_mkdir? should return false" do
|
611
614
|
@quilt.can_mkdir?("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows").should be_false
|
@@ -613,71 +616,71 @@ describe "Quilt" do
|
|
613
616
|
it "can_rmdir? should return false" do
|
614
617
|
@quilt.can_rmdir?("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows").should be_false
|
615
618
|
end
|
616
|
-
describe "
|
619
|
+
describe "0i/" do
|
617
620
|
it "directory? should return true" do
|
618
|
-
@quilt.directory?("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows/
|
621
|
+
@quilt.directory?("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows/0i").should be_true
|
619
622
|
end
|
620
623
|
it "file? should return false" do
|
621
|
-
@quilt.file?("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows/
|
624
|
+
@quilt.file?("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows/0i").should be_false
|
622
625
|
end
|
623
626
|
it "contents should list view result row content" do
|
624
|
-
@quilt.contents("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows/
|
627
|
+
@quilt.contents("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows/0i").should == ["id.js", "key.js", "value.js"]
|
625
628
|
end
|
626
629
|
it "can_mkdir? should return false" do
|
627
|
-
@quilt.can_mkdir?("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows/
|
630
|
+
@quilt.can_mkdir?("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows/0i").should be_false
|
628
631
|
end
|
629
632
|
it "can_rmdir? should return false" do
|
630
|
-
@quilt.can_rmdir?("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows/
|
633
|
+
@quilt.can_rmdir?("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows/0i").should be_false
|
631
634
|
end
|
632
635
|
describe "id.js" do
|
633
636
|
it "directory? should return false" do
|
634
|
-
@quilt.directory?("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows/
|
637
|
+
@quilt.directory?("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows/0i/id.js").should be_false
|
635
638
|
end
|
636
639
|
it "file? should return true" do
|
637
|
-
@quilt.file?("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows/
|
640
|
+
@quilt.file?("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows/0i/id.js").should be_true
|
638
641
|
end
|
639
642
|
it "read_file should return contents" do
|
640
|
-
@quilt.read_file("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows/
|
643
|
+
@quilt.read_file("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows/0i/id.js").should == "document_id"
|
641
644
|
end
|
642
645
|
it "can_write? should return false" do
|
643
|
-
@quilt.can_write?("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows/
|
646
|
+
@quilt.can_write?("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows/0i/id.js").should be_false
|
644
647
|
end
|
645
648
|
it "can_delete? should return false" do
|
646
|
-
@quilt.can_delete?("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows/
|
649
|
+
@quilt.can_delete?("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows/0i/id.js").should be_false
|
647
650
|
end
|
648
651
|
end
|
649
652
|
describe "key.js" do
|
650
653
|
it "directory? should return false" do
|
651
|
-
@quilt.directory?("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows/
|
654
|
+
@quilt.directory?("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows/0i/key.js").should be_false
|
652
655
|
end
|
653
656
|
it "file? should return true" do
|
654
|
-
@quilt.file?("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows/
|
657
|
+
@quilt.file?("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows/0i/key.js").should be_true
|
655
658
|
end
|
656
659
|
it "read_file should return contents" do
|
657
|
-
@quilt.read_file("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows/
|
660
|
+
@quilt.read_file("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows/0i/key.js").should == "This is a name"
|
658
661
|
end
|
659
662
|
it "can_write? should return false" do
|
660
|
-
@quilt.can_write?("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows/
|
663
|
+
@quilt.can_write?("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows/0i/key.js").should be_false
|
661
664
|
end
|
662
665
|
it "can_delete? should return false" do
|
663
|
-
@quilt.can_delete?("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows/
|
666
|
+
@quilt.can_delete?("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows/0i/key.js").should be_false
|
664
667
|
end
|
665
668
|
end
|
666
669
|
describe "value.js" do
|
667
670
|
it "directory? should return false" do
|
668
|
-
@quilt.directory?("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows/
|
671
|
+
@quilt.directory?("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows/0i/value.js").should be_false
|
669
672
|
end
|
670
673
|
it "file? should return true" do
|
671
|
-
@quilt.file?("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows/
|
674
|
+
@quilt.file?("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows/0i/value.js").should be_true
|
672
675
|
end
|
673
676
|
it "read_file should return contents" do
|
674
|
-
@quilt.read_file("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows/
|
677
|
+
@quilt.read_file("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows/0i/value.js").should == ""
|
675
678
|
end
|
676
679
|
it "can_write? should return false" do
|
677
|
-
@quilt.can_write?("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows/
|
680
|
+
@quilt.can_write?("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows/0i/value.js").should be_false
|
678
681
|
end
|
679
682
|
it "can_delete? should return false" do
|
680
|
-
@quilt.can_delete?("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows/
|
683
|
+
@quilt.can_delete?("/#{TESTDB}/_design/design_document_id/_view/view_function_name/rows/0i/value.js").should be_false
|
681
684
|
end
|
682
685
|
end
|
683
686
|
end
|
@@ -687,5 +690,41 @@ describe "Quilt" do
|
|
687
690
|
end
|
688
691
|
end
|
689
692
|
end
|
693
|
+
|
694
|
+
# /_uuids
|
695
|
+
describe "_uuids/" do
|
696
|
+
it "directory? should return true" do
|
697
|
+
@quilt.directory?("/_uuids").should be_true
|
698
|
+
end
|
699
|
+
it "file? should return false" do
|
700
|
+
@quilt.file?("/_uuids").should be_false
|
701
|
+
end
|
702
|
+
it "can_mkdir? should return false" do
|
703
|
+
@quilt.can_mkdir?("/_uuids").should be_false
|
704
|
+
end
|
705
|
+
it "can_rmdir? should return false" do
|
706
|
+
@quilt.can_rmdir?("/_uuids").should be_false
|
707
|
+
end
|
708
|
+
it "contents should include 0i.js" do
|
709
|
+
@quilt.contents("/_uuids").should == ["0i.js"]
|
710
|
+
end
|
711
|
+
describe "0i.js" do
|
712
|
+
it "directory? should return false" do
|
713
|
+
@quilt.directory?("/_uuids/0i.js").should be_false
|
714
|
+
end
|
715
|
+
it "file? should return true" do
|
716
|
+
@quilt.file?("/_uuids/0i.js").should be_true
|
717
|
+
end
|
718
|
+
it "can_delete? should return false" do
|
719
|
+
@quilt.can_delete?("/_uuids/0i.js").should be_false
|
720
|
+
end
|
721
|
+
it "can_write? should return false" do
|
722
|
+
@quilt.can_write?("/_uuids/0i.js").should be_false
|
723
|
+
end
|
724
|
+
it "read_file should return contents" do
|
725
|
+
@quilt.read_file("/_uuids/0i.js").should =~ /\A[a-z0-9]{32}\z/
|
726
|
+
end
|
727
|
+
end
|
728
|
+
end
|
690
729
|
end
|
691
730
|
end
|