couchc 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +45 -0
- data/Rakefile +54 -0
- data/VERSION +1 -0
- data/bin/couchc +5 -0
- data/couchc.gemspec +63 -0
- data/lib/commands/all_documents.rb +21 -0
- data/lib/commands/delete.rb +28 -0
- data/lib/commands/new_doc.rb +17 -0
- data/lib/commands/show.rb +33 -0
- data/lib/commands/update.rb +27 -0
- data/lib/commands/uri.rb +17 -0
- data/lib/couchconsole.rb +78 -0
- data/test/helper.rb +9 -0
- data/test/test_couchc.rb +7 -0
- metadata +98 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 glejeune
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
= couchc
|
2
|
+
|
3
|
+
couchc is a tiny console for CouchDB
|
4
|
+
|
5
|
+
== ChangeLog
|
6
|
+
|
7
|
+
=== 0.1.0
|
8
|
+
* First public release
|
9
|
+
|
10
|
+
== Synopsis
|
11
|
+
|
12
|
+
$ couchc http://localhost:5984/database
|
13
|
+
>> help
|
14
|
+
help : Display this help
|
15
|
+
quit : Quit
|
16
|
+
documents : Show the document with id
|
17
|
+
_all_docs : Same as documents
|
18
|
+
delete id [field] : Delete the document with id or the field in the document
|
19
|
+
new_doc : Create a new document
|
20
|
+
show id : Show the document with id
|
21
|
+
update id field = value : Update (or add) the field with value in document id
|
22
|
+
uri id : Returns the CouchDB uri for the document
|
23
|
+
>>
|
24
|
+
|
25
|
+
== Requirements
|
26
|
+
|
27
|
+
* couchrest
|
28
|
+
|
29
|
+
== Install
|
30
|
+
|
31
|
+
sudo gem install couchc
|
32
|
+
|
33
|
+
== Note on Patches/Pull Requests
|
34
|
+
|
35
|
+
* Fork the project.
|
36
|
+
* Make your feature addition or bug fix.
|
37
|
+
* Add tests for it. This is important so I don't break it in a
|
38
|
+
future version unintentionally.
|
39
|
+
* Commit, do not mess with rakefile, version, or history.
|
40
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
41
|
+
* Send me a pull request. Bonus points for topic branches.
|
42
|
+
|
43
|
+
== Copyright
|
44
|
+
|
45
|
+
Copyright (c) 2010 glejeune. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
|
4
|
+
begin
|
5
|
+
require 'jeweler'
|
6
|
+
Jeweler::Tasks.new do |gem|
|
7
|
+
gem.name = "couchc"
|
8
|
+
gem.summary = %Q{couchc is a tiny console for CouchDB}
|
9
|
+
gem.description = %Q{couchc is a tiny console for CouchDB}
|
10
|
+
gem.email = "gregoire.lejeune@free.fr"
|
11
|
+
gem.homepage = "http://algorithmique.net"
|
12
|
+
gem.authors = ["glejeune"]
|
13
|
+
gem.bindir = "bin"
|
14
|
+
gem.executables = ['couchc']
|
15
|
+
gem.add_dependency('couchrest')
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'rake/testtask'
|
23
|
+
Rake::TestTask.new(:test) do |test|
|
24
|
+
test.libs << 'lib' << 'test'
|
25
|
+
test.pattern = 'test/**/test_*.rb'
|
26
|
+
test.verbose = true
|
27
|
+
end
|
28
|
+
|
29
|
+
begin
|
30
|
+
require 'rcov/rcovtask'
|
31
|
+
Rcov::RcovTask.new do |test|
|
32
|
+
test.libs << 'test'
|
33
|
+
test.pattern = 'test/**/test_*.rb'
|
34
|
+
test.verbose = true
|
35
|
+
end
|
36
|
+
rescue LoadError
|
37
|
+
task :rcov do
|
38
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
task :test => :check_dependencies
|
43
|
+
|
44
|
+
task :default => :test
|
45
|
+
|
46
|
+
require 'rake/rdoctask'
|
47
|
+
Rake::RDocTask.new do |rdoc|
|
48
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
49
|
+
|
50
|
+
rdoc.rdoc_dir = 'rdoc'
|
51
|
+
rdoc.title = "couchc #{version}"
|
52
|
+
rdoc.rdoc_files.include('README*')
|
53
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
54
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/couchc
ADDED
data/couchc.gemspec
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{couchc}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["glejeune"]
|
12
|
+
s.date = %q{2010-06-10}
|
13
|
+
s.default_executable = %q{couchc}
|
14
|
+
s.description = %q{couchc is a tiny console for CouchDB}
|
15
|
+
s.email = %q{gregoire.lejeune@free.fr}
|
16
|
+
s.executables = ["couchc"]
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE",
|
19
|
+
"README.rdoc"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
".gitignore",
|
24
|
+
"LICENSE",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"bin/couchc",
|
29
|
+
"couchc.gemspec",
|
30
|
+
"lib/commands/all_documents.rb",
|
31
|
+
"lib/commands/delete.rb",
|
32
|
+
"lib/commands/new_doc.rb",
|
33
|
+
"lib/commands/show.rb",
|
34
|
+
"lib/commands/update.rb",
|
35
|
+
"lib/commands/uri.rb",
|
36
|
+
"lib/couchconsole.rb",
|
37
|
+
"test/helper.rb",
|
38
|
+
"test/test_couchc.rb"
|
39
|
+
]
|
40
|
+
s.homepage = %q{http://algorithmique.net}
|
41
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
42
|
+
s.require_paths = ["lib"]
|
43
|
+
s.rubygems_version = %q{1.3.7}
|
44
|
+
s.summary = %q{couchc is a tiny console for CouchDB}
|
45
|
+
s.test_files = [
|
46
|
+
"test/helper.rb",
|
47
|
+
"test/test_couchc.rb"
|
48
|
+
]
|
49
|
+
|
50
|
+
if s.respond_to? :specification_version then
|
51
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
52
|
+
s.specification_version = 3
|
53
|
+
|
54
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
55
|
+
s.add_runtime_dependency(%q<couchrest>, [">= 0"])
|
56
|
+
else
|
57
|
+
s.add_dependency(%q<couchrest>, [">= 0"])
|
58
|
+
end
|
59
|
+
else
|
60
|
+
s.add_dependency(%q<couchrest>, [">= 0"])
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class CouchConsole
|
2
|
+
def init
|
3
|
+
puts "** initialize all_documents"
|
4
|
+
@commands << {
|
5
|
+
:regexp => /documents|all_docs/,
|
6
|
+
:method => :allDocuments,
|
7
|
+
:documentation => [
|
8
|
+
["documents", "Show the document with id"],
|
9
|
+
["_all_docs", "Same as documents"]
|
10
|
+
]
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
def allDocuments
|
15
|
+
all = @db.documents
|
16
|
+
puts "#{all["total_rows"]} documents :"
|
17
|
+
all["rows"].each do |doc|
|
18
|
+
puts " id : #{doc["id"]} - rev : #{doc["value"]["rev"]}"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class CouchConsole
|
2
|
+
def init
|
3
|
+
puts "** initialize delete"
|
4
|
+
@commands << {
|
5
|
+
:regexp => /^\s*delete\s*([^\s]*)\s*([^\s]*)\s*$/,
|
6
|
+
:method => :delete,
|
7
|
+
:documentation => [["delete id [field]", "Delete the document with id or the field in the document"]]
|
8
|
+
}
|
9
|
+
end
|
10
|
+
|
11
|
+
def delete( id, field )
|
12
|
+
document = @db.get( id )
|
13
|
+
if field.size > 0
|
14
|
+
document.delete(field)
|
15
|
+
document.save
|
16
|
+
puts "*** Field `#{field}' deleted in document `#{id}'"
|
17
|
+
else
|
18
|
+
if document.class == CouchRest::Document
|
19
|
+
document.destroy
|
20
|
+
puts "*** Document `#{id}' deleted"
|
21
|
+
else
|
22
|
+
puts "!!! Can't delete document `#{id}'"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
rescue RestClient::ResourceNotFound
|
26
|
+
puts "!!! Document `#{id}' does not exist."
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class CouchConsole
|
2
|
+
def init
|
3
|
+
puts "** initialize create"
|
4
|
+
@commands << {
|
5
|
+
:regexp => /^\s*new_doc\s*$/,
|
6
|
+
:method => :new_doc,
|
7
|
+
:documentation => [["new_doc", "Create a new document"]]
|
8
|
+
}
|
9
|
+
end
|
10
|
+
|
11
|
+
def new_doc
|
12
|
+
document = CouchRest::Document.new
|
13
|
+
document.database = @db
|
14
|
+
document.save
|
15
|
+
puts "** Document `#{document.id}' created!"
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class CouchConsole
|
2
|
+
def init
|
3
|
+
puts "** initialize show"
|
4
|
+
@commands << {
|
5
|
+
:regexp => /^\s*show\s*(.*)\s*$/,
|
6
|
+
:method => :show,
|
7
|
+
:documentation => [["show id", "Show the document with id"]]
|
8
|
+
}
|
9
|
+
end
|
10
|
+
|
11
|
+
def showDesign( doc )
|
12
|
+
puts "!!! Show design is not yet implemented"
|
13
|
+
end
|
14
|
+
|
15
|
+
def showDocument( doc )
|
16
|
+
size = 0
|
17
|
+
doc.keys.each { |k| size = k.size if k.size > size}
|
18
|
+
doc.each do |k, v|
|
19
|
+
printf "%#{size}s : %s\n", k, v
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def show( id )
|
24
|
+
document = @db.get( id )
|
25
|
+
if document.class == CouchRest::Document
|
26
|
+
showDocument( document )
|
27
|
+
else
|
28
|
+
showDesign( document )
|
29
|
+
end
|
30
|
+
rescue RestClient::ResourceNotFound
|
31
|
+
puts "!!! Document `#{id}' does not exist."
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class CouchConsole
|
2
|
+
def init
|
3
|
+
puts "** initialize update"
|
4
|
+
@commands << {
|
5
|
+
:regexp => /^\s*update\s*([^\s]*)\s*([^\s=]*)\s*=\s*([^\s]*)\s*$/,
|
6
|
+
:method => :update,
|
7
|
+
:documentation => [["update id field = value", "Update (or add) the field with value in document id"]]
|
8
|
+
}
|
9
|
+
end
|
10
|
+
|
11
|
+
def update( id, field, value )
|
12
|
+
document = @db.get( id )
|
13
|
+
if document.class == CouchRest::Document
|
14
|
+
document[field] = value
|
15
|
+
begin
|
16
|
+
document.save
|
17
|
+
puts "*** Update `#{id}' : #{field} = #{value}"
|
18
|
+
rescue => e
|
19
|
+
puts "!!! Update `#{id}' faild with message #{e.message}"
|
20
|
+
end
|
21
|
+
else
|
22
|
+
puts "!!! Can't update `#{id}'"
|
23
|
+
end
|
24
|
+
rescue RestClient::ResourceNotFound
|
25
|
+
puts "!!! Document `#{id}' does not exist."
|
26
|
+
end
|
27
|
+
end
|
data/lib/commands/uri.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
class CouchConsole
|
2
|
+
def init
|
3
|
+
puts "** initialize uri"
|
4
|
+
@commands << {
|
5
|
+
:regexp => /^\s*uri\s*(.*)\s*$/,
|
6
|
+
:method => :uri,
|
7
|
+
:documentation => [["uri id", "Returns the CouchDB uri for the document"]]
|
8
|
+
}
|
9
|
+
end
|
10
|
+
|
11
|
+
def uri( id )
|
12
|
+
document = @db.get( id )
|
13
|
+
puts document.uri
|
14
|
+
rescue RestClient::ResourceNotFound
|
15
|
+
puts "!!! Document `#{id}' does not exist."
|
16
|
+
end
|
17
|
+
end
|
data/lib/couchconsole.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'couchrest'
|
2
|
+
require 'readline'
|
3
|
+
|
4
|
+
class CouchConsole
|
5
|
+
def initialize
|
6
|
+
@commands = [
|
7
|
+
{
|
8
|
+
:regexp => /^\s*help\s*$/,
|
9
|
+
:method => :help,
|
10
|
+
:documentation => [["help", "Display this help"]]
|
11
|
+
},
|
12
|
+
{
|
13
|
+
:regexp => /^\s*quit\s*$/,
|
14
|
+
:method => nil,
|
15
|
+
:documentation => [["quit", "Quit"]]
|
16
|
+
}
|
17
|
+
]
|
18
|
+
Dir.glob( File.join(File.dirname(File.expand_path(__FILE__)), "commands", "*.rb") ).each do |file|
|
19
|
+
require file
|
20
|
+
init
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def getDatabase
|
25
|
+
print "Database URI : ";
|
26
|
+
$stdin.readline.chomp
|
27
|
+
end
|
28
|
+
|
29
|
+
def help
|
30
|
+
@commands.each do |command|
|
31
|
+
command[:documentation].each do |cmd|
|
32
|
+
printf "%-30s : %s\n", cmd[0], cmd[1]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def execute( cmd )
|
38
|
+
executed = 0
|
39
|
+
@commands.each do |command|
|
40
|
+
if match = command[:regexp].match(cmd)
|
41
|
+
executed += 1
|
42
|
+
params = match.captures
|
43
|
+
if params.size > 0
|
44
|
+
self.send command[:method], *params
|
45
|
+
else
|
46
|
+
self.send command[:method]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
if executed == 0
|
51
|
+
puts "!!! Command unknown. Try help"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def go
|
56
|
+
base = ARGV[0] || getDatabase
|
57
|
+
|
58
|
+
@db = CouchRest.database!( base )
|
59
|
+
begin
|
60
|
+
@db.info
|
61
|
+
rescue Errno::ECONNREFUSED
|
62
|
+
puts "!!! Can acces database #{@db}"
|
63
|
+
return
|
64
|
+
end
|
65
|
+
|
66
|
+
prompt = ">> "
|
67
|
+
while( true )
|
68
|
+
cmd = Readline.readline(prompt, true)
|
69
|
+
break if cmd.nil? or cmd.chomp == "quit"
|
70
|
+
execute( cmd )
|
71
|
+
end
|
72
|
+
puts "\nBye! Bye !\n"
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.go
|
76
|
+
CouchConsole.new.go
|
77
|
+
end
|
78
|
+
end
|
data/test/helper.rb
ADDED
data/test/test_couchc.rb
ADDED
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: couchc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- glejeune
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-06-10 00:00:00 +02:00
|
19
|
+
default_executable: couchc
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: couchrest
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
description: couchc is a tiny console for CouchDB
|
36
|
+
email: gregoire.lejeune@free.fr
|
37
|
+
executables:
|
38
|
+
- couchc
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- LICENSE
|
43
|
+
- README.rdoc
|
44
|
+
files:
|
45
|
+
- .document
|
46
|
+
- .gitignore
|
47
|
+
- LICENSE
|
48
|
+
- README.rdoc
|
49
|
+
- Rakefile
|
50
|
+
- VERSION
|
51
|
+
- bin/couchc
|
52
|
+
- couchc.gemspec
|
53
|
+
- lib/commands/all_documents.rb
|
54
|
+
- lib/commands/delete.rb
|
55
|
+
- lib/commands/new_doc.rb
|
56
|
+
- lib/commands/show.rb
|
57
|
+
- lib/commands/update.rb
|
58
|
+
- lib/commands/uri.rb
|
59
|
+
- lib/couchconsole.rb
|
60
|
+
- test/helper.rb
|
61
|
+
- test/test_couchc.rb
|
62
|
+
has_rdoc: true
|
63
|
+
homepage: http://algorithmique.net
|
64
|
+
licenses: []
|
65
|
+
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options:
|
68
|
+
- --charset=UTF-8
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
hash: 3
|
77
|
+
segments:
|
78
|
+
- 0
|
79
|
+
version: "0"
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
hash: 3
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
version: "0"
|
89
|
+
requirements: []
|
90
|
+
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 1.3.7
|
93
|
+
signing_key:
|
94
|
+
specification_version: 3
|
95
|
+
summary: couchc is a tiny console for CouchDB
|
96
|
+
test_files:
|
97
|
+
- test/helper.rb
|
98
|
+
- test/test_couchc.rb
|