couchup 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/couchup/commands/connect.rb +14 -12
- data/lib/couchup/commands/create.rb +13 -0
- data/lib/couchup/commands/get.rb +10 -8
- data/lib/couchup/commands/help.rb +13 -10
- data/lib/couchup/commands/map.rb +13 -0
- data/lib/couchup/commands/restart.rb +13 -0
- data/lib/couchup/commands/show.rb +15 -8
- data/lib/couchup/commands/use.rb +14 -10
- data/lib/couchup/commands/view.rb +13 -0
- data/lib/couchup/couchup.rb +42 -32
- data/lib/couchup/extensions/array.rb +5 -0
- data/lib/couchup/extensions/string.rb +5 -0
- data/lib/couchup/extensions/symbol.rb +3 -0
- data/lib/couchup/mapreduce.rb +27 -0
- data/lib/couchup/version.rb +1 -1
- data/lib/couchup.rb +8 -3
- metadata +9 -2
@@ -1,16 +1,18 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
1
|
+
module Couchup
|
2
|
+
module Commands
|
3
|
+
class Connect
|
4
|
+
def run(host = 'localhost', port = 5984)
|
5
|
+
Couchup.host = host
|
6
|
+
Couchup.port = port
|
7
|
+
if(Couchup.ready?)
|
8
|
+
puts "Connected to #{Couchup.host}:#{Couchup.port}"
|
9
|
+
else
|
10
|
+
puts "Could not connect to #{Couchup.host}:#{Couchup.port}"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
def self.describe
|
14
|
+
"Connects to the couch server. Takes host and port defaults to 5984"
|
10
15
|
end
|
11
|
-
end
|
12
|
-
def self.describe
|
13
|
-
"Connects to the couch server. Takes host and port defaults to 5984"
|
14
16
|
end
|
15
17
|
end
|
16
18
|
end
|
data/lib/couchup/commands/get.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
id
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
module Couchup
|
2
|
+
module Commands
|
3
|
+
class Get
|
4
|
+
def run(id = nil)
|
5
|
+
id.nil? ? Couchup.all : Couchup.get(id)
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.describe
|
9
|
+
"get [id] retuns the document with the id"
|
10
|
+
end
|
9
11
|
end
|
10
12
|
end
|
11
13
|
end
|
@@ -1,15 +1,18 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
1
|
+
module Couchup
|
2
|
+
module Commands
|
3
|
+
class Help
|
4
|
+
def run(param = nil)
|
5
|
+
commands = param.nil? ? Commands.constants : [param.camelize]
|
6
|
+
commands.each do |stuff|
|
7
|
+
k = Commands.const_get(stuff)
|
8
|
+
print stuff.downcase; print "\t\t"
|
9
|
+
puts k.respond_to?(:describe) ? k.describe : "No Help"
|
10
|
+
end
|
8
11
|
end
|
9
|
-
end
|
10
12
|
|
11
|
-
|
12
|
-
|
13
|
+
def self.describe
|
14
|
+
"Help on the system, 'help :get' will provider help about using get."
|
15
|
+
end
|
13
16
|
end
|
14
17
|
end
|
15
18
|
end
|
@@ -1,11 +1,18 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
module Couchup
|
2
|
+
module Commands
|
3
|
+
class Show
|
4
|
+
def run(param)
|
5
|
+
param = param.to_s
|
6
|
+
if(param.blank? || param == 'databases' )
|
7
|
+
puts Couchup.databases.inspect
|
8
|
+
else
|
9
|
+
puts Couchup.views.inspect
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.describe
|
14
|
+
"show databases if databases is specified or views if vies is specified. defaults to databases."
|
15
|
+
end
|
9
16
|
end
|
10
17
|
end
|
11
18
|
end
|
data/lib/couchup/commands/use.rb
CHANGED
@@ -1,16 +1,20 @@
|
|
1
|
-
module
|
2
|
-
|
3
|
-
|
1
|
+
module Couchup
|
2
|
+
module Commands
|
3
|
+
class Use
|
4
|
+
def run(database)
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
if Couchup.databases.include? database
|
7
|
+
Couchup.database = database
|
8
|
+
puts Couchup.database.info.inspect
|
9
|
+
else
|
10
|
+
puts "Database was not found"
|
11
|
+
end
|
9
12
|
end
|
10
|
-
end
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
+
def self.describe
|
15
|
+
"Use provided database"
|
16
|
+
end
|
14
17
|
end
|
15
18
|
end
|
19
|
+
|
16
20
|
end
|
data/lib/couchup/couchup.rb
CHANGED
@@ -1,40 +1,50 @@
|
|
1
|
-
|
2
|
-
class
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
def database=(database)
|
9
|
-
@db = CouchRest.database!("http://#{host}:#{port}/#{database}")
|
10
|
-
end
|
1
|
+
module Couchup
|
2
|
+
class Couchup
|
3
|
+
class << self
|
4
|
+
attr_accessor :port, :host
|
5
|
+
def server
|
6
|
+
@server ||= CouchRest::Server.new("http://#{host}:#{port}")
|
7
|
+
end
|
11
8
|
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
def database=(database)
|
10
|
+
@db = CouchRest.database!("http://#{host}:#{port}/#{database}")
|
11
|
+
end
|
15
12
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
13
|
+
def database
|
14
|
+
@db
|
15
|
+
end
|
16
|
+
|
17
|
+
def views(design = nil)
|
18
|
+
params = design.nil? ? {:startkey => '_design', :endkey => '_design0'} : {:key => "_design\\#{design}"}
|
19
|
+
designs = database.documents(params.merge(:include_docs => true))["rows"]
|
20
|
+
designs.collect do |d|
|
21
|
+
d["doc"]["views"].keys
|
22
|
+
end.flatten
|
23
|
+
end
|
24
|
+
|
25
|
+
def ready?
|
26
|
+
uuid = nil
|
27
|
+
begin
|
28
|
+
puts (info = server.info)
|
29
|
+
rescue
|
30
|
+
puts $!.backtrace
|
31
|
+
puts $!.inspect
|
32
|
+
end
|
33
|
+
!info.nil?
|
34
|
+
end
|
26
35
|
|
27
|
-
|
28
|
-
|
29
|
-
|
36
|
+
def get(id)
|
37
|
+
@db.get(id)
|
38
|
+
end
|
30
39
|
|
31
|
-
|
32
|
-
|
33
|
-
|
40
|
+
def all(options={})
|
41
|
+
@db.documents
|
42
|
+
end
|
34
43
|
|
35
|
-
|
36
|
-
|
37
|
-
|
44
|
+
def databases
|
45
|
+
server.databases
|
46
|
+
end
|
38
47
|
|
48
|
+
end
|
39
49
|
end
|
40
50
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Couchup
|
2
|
+
class MapReduce
|
3
|
+
def self.map(*params)
|
4
|
+
view({}, *params)
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.reduce(*params)
|
8
|
+
view({:reduce => true}, *params)
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
def self.view(options, *params)
|
13
|
+
name = params.shift
|
14
|
+
view_params = {:include_docs => true}.merge(options)
|
15
|
+
if params.size == 1
|
16
|
+
val = params.first
|
17
|
+
view_params.merge!(:keys => val) if val.is_a? Array
|
18
|
+
view_params.merge!(val) if val.is_a? Hash
|
19
|
+
view_params.merge!(:key => val) unless val.nil?
|
20
|
+
end
|
21
|
+
response = Couchup.database.view(name, view_params)
|
22
|
+
rows = response["rows"]
|
23
|
+
puts "Found #{rows.size} items"
|
24
|
+
rows.each{|r| puts r.inspect}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/couchup/version.rb
CHANGED
data/lib/couchup.rb
CHANGED
@@ -1,13 +1,18 @@
|
|
1
1
|
require File.expand_path '../couchup/couchup', __FILE__
|
2
2
|
Dir[File.expand_path('../couchup/commands/*.rb',__FILE__)].each { |file| require file}
|
3
3
|
Dir[File.expand_path('../couchup/extensions/*.rb',__FILE__)].each { |file| require file}
|
4
|
+
Dir[File.expand_path('../couchup/*.rb',__FILE__)].each { |file| require file}
|
4
5
|
|
5
6
|
|
6
|
-
Commands.constants.each do |c|
|
7
|
+
Couchup::Commands.constants.each do |c|
|
7
8
|
instance_eval "
|
8
9
|
def #{c.underscore}(*args)
|
9
|
-
|
10
|
-
|
10
|
+
begin
|
11
|
+
instance = Couchup::Commands.const_get(:#{c}).new
|
12
|
+
instance.run(*args)
|
13
|
+
rescue
|
14
|
+
puts $!.inspect
|
15
|
+
end
|
11
16
|
end"
|
12
17
|
end
|
13
18
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: couchup
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- V Sreekanth
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-02-
|
13
|
+
date: 2011-02-24 00:00:00 +05:30
|
14
14
|
default_executable: ey
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -121,12 +121,19 @@ files:
|
|
121
121
|
- couchup.gemspec
|
122
122
|
- lib/couchup.rb
|
123
123
|
- lib/couchup/commands/connect.rb
|
124
|
+
- lib/couchup/commands/create.rb
|
124
125
|
- lib/couchup/commands/get.rb
|
125
126
|
- lib/couchup/commands/help.rb
|
127
|
+
- lib/couchup/commands/map.rb
|
128
|
+
- lib/couchup/commands/restart.rb
|
126
129
|
- lib/couchup/commands/show.rb
|
127
130
|
- lib/couchup/commands/use.rb
|
131
|
+
- lib/couchup/commands/view.rb
|
128
132
|
- lib/couchup/couchup.rb
|
133
|
+
- lib/couchup/extensions/array.rb
|
134
|
+
- lib/couchup/extensions/string.rb
|
129
135
|
- lib/couchup/extensions/symbol.rb
|
136
|
+
- lib/couchup/mapreduce.rb
|
130
137
|
- lib/couchup/version.rb
|
131
138
|
has_rdoc: true
|
132
139
|
homepage: ""
|