lsegal-couchio 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/LICENSE +22 -0
  2. data/README.markdown +99 -0
  3. data/Rakefile +31 -0
  4. metadata +64 -0
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2008 Loren Segal
2
+
3
+ Permission is hereby granted, free of charge, to any person
4
+ obtaining a copy of this software and associated documentation
5
+ files (the "Software"), to deal in the Software without
6
+ restriction, including without limitation the rights to use,
7
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the
9
+ Software is furnished to do so, subject to the following
10
+ conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,99 @@
1
+ CouchIO for Ruby
2
+ ================
3
+
4
+ Written by Loren Segal in 2008, licensed under MIT license.
5
+
6
+
7
+ SYNOPSYS
8
+ --------
9
+
10
+ CouchIO is a simple VFS for Ruby, adding support to open, read and write
11
+ CouchDB resource URI's as if they were local files. The API intuitively uses
12
+ the existing `File` and `Dir` API to read and write. The goal is to emulate
13
+ Ruby's `Dir` and `File` implementation for the filesystem completely. Not all of
14
+ the interface has been implemented, but basic read/write support is currently
15
+ available. In addition to database support, CouchIO has support for both documents
16
+ and attachments.
17
+
18
+
19
+ USAGE
20
+ -----
21
+
22
+ ### Accessing Databases & Documents ###
23
+
24
+ In CouchIO, the `Dir` filesystem equivalent of a directory is a CouchDB database.
25
+ The equivalent of a `File` is a CouchDB document *or* a CouchDB attachment, depending
26
+ on how the data is written.
27
+
28
+ The only difference between accessing files and directories and accessing documents and
29
+ databases is that you need to specify the full URI including the "couch://" scheme prefix,
30
+ not "http://" (to differentiate from `open-uri` support).
31
+
32
+ ### Writing Documents & Attachments ###
33
+
34
+ Like with writing to files, you need to use the 'a' append mode flag if you wish to append
35
+ to the file. If you do not use this for a Couch resource, it will overwrite all of your contents.
36
+
37
+ To write data to a document, your data **must** be a `Hash`. To write data to an _attachment_,
38
+ your data must be a `String`. As you will see in the examples, writing a string will force
39
+ the resource to be saved as an attachment while writing hash contents will save it as a document.
40
+
41
+ ### Note About Saving ###
42
+
43
+ Saving is done when the file is closed. There is a `save` method that can be manually called,
44
+ however, to maintain filesystem independence, it should never be called.
45
+
46
+
47
+ EXAMPLES
48
+ --------
49
+
50
+ List databases:
51
+
52
+ Dir.entries("couch://localhost:5984/") #=> ['todo', 'test']
53
+
54
+ Create a database:
55
+
56
+ Dir.mkdir("couch://localhost:5984/xyzzy")
57
+
58
+ Delete a database:
59
+
60
+ Dir.unlink("couch://localhost:5984/xyzzy")
61
+
62
+ List documents in a database:
63
+
64
+ Dir.entries("couch://localhost:5984/todo") #=> ['fix_car', 'wash_dishes', ...]
65
+ # - OR -
66
+ Dir.open("couch://localhost:5984/todo").each do |p|
67
+ puts p
68
+ end
69
+
70
+ Open and read a document:
71
+
72
+ File.open("couch://localhost:5984/todo/fix_car").read
73
+ #=> {'_id' => 'fix_car', 'text' => 'Need to fix car!', 'time' => 'June 20th 2008 10:55AM'}
74
+ # Same as: File.read("couch://localhost:5984/todo/fix_car")
75
+
76
+ Open a document for append-writing:
77
+
78
+ File.open("couch://localhost:5984/todo/fix_car", 'wa') do |f|
79
+ f.write 'text' => 'Need to fix car NOW!!!'
80
+ end
81
+ File.read("couch://localhost:5984/todo/fix_car")
82
+ #=> {'_id' => 'fix_car', 'text' => 'Need to fix car NOW!!!', 'time' => 'June 20th 2008 10:55AM'}
83
+
84
+ Write an attachment (document must exist):
85
+
86
+ File.open("couch://localhost:5984/test/doc/foo.txt", 'w') do |f|
87
+ f.write "hello world"
88
+ end
89
+
90
+ Read an attachment:
91
+
92
+ File.read("couch://localhost:5984/test/doc/foo.txt") #=> "hello world"
93
+
94
+
95
+ COPYRIGHT
96
+ ---------
97
+
98
+ CouchIO is free software written by **Loren Segal** under the MIT license. If
99
+ you meet him, give him props.
@@ -0,0 +1,31 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+ require 'spec'
4
+ require 'spec/rake/spectask'
5
+ require 'yard'
6
+
7
+ WINDOWS = (PLATFORM =~ /win32|cygwin/ ? true : false) rescue false
8
+ SUDO = WINDOWS ? '' : 'sudo'
9
+
10
+ task :default => :specs
11
+
12
+ load 'couchio.gemspec'
13
+ Rake::GemPackageTask.new(SPEC) do |pkg|
14
+ pkg.gem_spec = SPEC
15
+ pkg.need_zip = true
16
+ pkg.need_tar = true
17
+ end
18
+
19
+ desc "Install the gem locally"
20
+ task :install => :package do
21
+ sh "#{SUDO} gem install pkg/#{SPEC.name}-#{SPEC.version}.gem --local"
22
+ end
23
+
24
+ desc "Run all specs"
25
+ Spec::Rake::SpecTask.new("specs") do |t|
26
+ $DEBUG = true if ENV['DEBUG']
27
+ t.spec_opts = ["--format", "specdoc", "--colour"]
28
+ t.spec_files = Dir["spec/**/*_spec.rb"].sort
29
+ end
30
+
31
+ YARD::Rake::YardocTask.new
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lsegal-couchio
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Loren Segal
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-05-20 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: json
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description:
26
+ email: lsegal@soen.ca
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - LICENSE
35
+ - README.markdown
36
+ - Rakefile
37
+ has_rdoc: yard
38
+ homepage: http://couchio.soen.ca
39
+ post_install_message:
40
+ rdoc_options: []
41
+
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ version:
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: "0"
55
+ version:
56
+ requirements: []
57
+
58
+ rubyforge_project: couchio
59
+ rubygems_version: 1.2.0
60
+ signing_key:
61
+ specification_version: 2
62
+ summary: Virtual filesystem support for a CouchDB database.
63
+ test_files: []
64
+