couchup 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/TODO +3 -0
- data/bin/couchup +2 -2
- data/lib/couchup/commands/compact.rb +12 -0
- data/lib/couchup/commands/create.rb +29 -2
- data/lib/couchup/commands/drop.rb +14 -0
- data/lib/couchup/commands/get.rb +1 -1
- data/lib/couchup/commands/help.rb +1 -1
- data/lib/couchup/commands/replicate_to.rb +18 -0
- data/lib/couchup/commands/show.rb +4 -4
- data/lib/couchup/commands/use.rb +3 -3
- data/lib/couchup/couchup.rb +1 -1
- data/lib/couchup/mapreduce.rb +6 -1
- data/lib/couchup/version.rb +1 -1
- data/lib/couchup/view.rb +30 -0
- metadata +7 -2
data/bin/couchup
CHANGED
@@ -2,9 +2,36 @@ module Couchup
|
|
2
2
|
module Commands
|
3
3
|
class Create
|
4
4
|
def run(*params)
|
5
|
-
|
6
|
-
|
5
|
+
what = params.shift.to_s
|
6
|
+
if(what == 'view')
|
7
|
+
create_view(params.first)
|
8
|
+
else
|
9
|
+
Couchup.server.database!(params.first)
|
10
|
+
Use.new.run(params.first)
|
11
|
+
end
|
7
12
|
end
|
13
|
+
|
14
|
+
def create_view(name)
|
15
|
+
raise "Please set your EDITOR env variable before using view" if ENV['EDITOR'].nil?
|
16
|
+
view = View.new(name)
|
17
|
+
file = Tempfile.new(name.gsub("/", "_"))
|
18
|
+
tmp_file_path = file.path
|
19
|
+
file.write("------BEGIN Map-------\n")
|
20
|
+
file.write(view.map) if view.map?
|
21
|
+
file.write("------END------\n\n")
|
22
|
+
|
23
|
+
file.write("------BEGIN Reduce(Remove the function if you don't want a reduce)-------\n")
|
24
|
+
file.write(view.reduce) if view.reduce?
|
25
|
+
file.write("------END------\n")
|
26
|
+
file.close
|
27
|
+
|
28
|
+
`#{ENV['EDITOR']} #{tmp_file_path}`
|
29
|
+
contents = File.open(tmp_file_path).read
|
30
|
+
::Couchup::View.create(name, contents)
|
31
|
+
file.close
|
32
|
+
file.unlink
|
33
|
+
end
|
34
|
+
|
8
35
|
def self.describe
|
9
36
|
"Creates a new database and switches to the database"
|
10
37
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Couchup
|
2
|
+
module Commands
|
3
|
+
class Drop
|
4
|
+
def run(*params)
|
5
|
+
db = params.first.nil? ? Couchup.server.database : Couchup.server.database(params.first)
|
6
|
+
db.delete!
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.describe
|
10
|
+
"Drops a database. Use it with drop <dbname>"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/couchup/commands/get.rb
CHANGED
@@ -5,7 +5,7 @@ module Couchup
|
|
5
5
|
commands = param.nil? ? Commands.constants : [param.camelize]
|
6
6
|
commands.each do |stuff|
|
7
7
|
k = Commands.const_get(stuff)
|
8
|
-
print stuff.
|
8
|
+
print stuff.underscore; print "\t\t"
|
9
9
|
puts k.respond_to?(:describe) ? k.describe : "No Help"
|
10
10
|
end
|
11
11
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Couchup
|
2
|
+
module Commands
|
3
|
+
class ReplicateTo
|
4
|
+
def run(*params)
|
5
|
+
dest = params.shift
|
6
|
+
option = params.shift
|
7
|
+
dest_db = (dest =~ /(http:\/\/.*)\/(.*)/) ? CouchRest::Database.new(CouchRest::Server.new($1), $2) : CouchRest::Database.new(Couchup.server, dest)
|
8
|
+
Couchup.database.replicate_to dest_db, (option.to_s == "continous")
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.describe
|
12
|
+
"Allows replication to different databases. Try replicate_to 'http://foo.bar.com:5984/billing' :continous"
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
module Couchup
|
2
2
|
module Commands
|
3
3
|
class Show
|
4
|
-
def run(param)
|
5
|
-
|
6
|
-
if(
|
4
|
+
def run(*param)
|
5
|
+
option = param.first.to_s
|
6
|
+
if(option.blank? || option == 'databases' )
|
7
7
|
puts Couchup.databases.inspect
|
8
8
|
else
|
9
|
-
puts Couchup.views.inspect
|
9
|
+
puts Couchup.views(param.second).inspect
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
data/lib/couchup/commands/use.rb
CHANGED
@@ -2,9 +2,9 @@ module Couchup
|
|
2
2
|
module Commands
|
3
3
|
class Use
|
4
4
|
def run(database)
|
5
|
-
|
6
|
-
if Couchup.databases.include?
|
7
|
-
Couchup.database =
|
5
|
+
db = database.to_s
|
6
|
+
if Couchup.databases.include? db
|
7
|
+
Couchup.database = db
|
8
8
|
puts Couchup.database.info.inspect
|
9
9
|
else
|
10
10
|
puts "Database was not found"
|
data/lib/couchup/couchup.rb
CHANGED
@@ -18,7 +18,7 @@ module Couchup
|
|
18
18
|
params = design.nil? ? {:startkey => '_design', :endkey => '_design0'} : {:key => "_design\\#{design}"}
|
19
19
|
designs = database.documents(params.merge(:include_docs => true))["rows"]
|
20
20
|
designs.collect do |d|
|
21
|
-
d["doc"]["views"].keys
|
21
|
+
d["doc"]["views"].keys.collect{|view| "#{d['key'].gsub('_design/','')}/#{view}"}
|
22
22
|
end.flatten
|
23
23
|
end
|
24
24
|
|
data/lib/couchup/mapreduce.rb
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
module Couchup
|
2
2
|
class MapReduce
|
3
3
|
def self.map(*params)
|
4
|
-
view
|
4
|
+
#FIXME. should probably get view meta data to do one view call. but this is also doing 2 calls.
|
5
|
+
begin
|
6
|
+
view({}, *params)
|
7
|
+
rescue RestClient::BadRequest
|
8
|
+
view({:reduce => false}, *params)
|
9
|
+
end
|
5
10
|
end
|
6
11
|
|
7
12
|
def self.reduce(*params)
|
data/lib/couchup/version.rb
CHANGED
data/lib/couchup/view.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
module Couchup
|
2
|
+
class View
|
3
|
+
|
4
|
+
def initialize(name)
|
5
|
+
@design, @name = name.split "/"
|
6
|
+
design, name = name.split "/"
|
7
|
+
begin
|
8
|
+
doc = Couchup.database.get("_design/#{design}")
|
9
|
+
rescue
|
10
|
+
# handle creation of new design doc.
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.create(name, file_contents)
|
15
|
+
v = doc["views"][name]
|
16
|
+
map, reduce = parse(file_contents)
|
17
|
+
|
18
|
+
puts "View Exists overwriting." unless v.nil?
|
19
|
+
v = (doc["views"][name]= {}) if v.nil?
|
20
|
+
v["map"] = map
|
21
|
+
v["reduce"] = reduce unless reduce.blank?
|
22
|
+
Couchup.database.save_doc(doc)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.parse(file_contents)
|
26
|
+
file_contents =~ /-+BEGIN Map-+(.*)^-+END-+.*BEGIN Reduce.*-+(.*)^-+END-*/m
|
27
|
+
[$1.strip, $2.strip]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
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.8
|
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-25 00:00:00 +05:30
|
14
14
|
default_executable: ey
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -117,14 +117,18 @@ files:
|
|
117
117
|
- Gemfile.lock
|
118
118
|
- Rakefile
|
119
119
|
- Readme.markdown
|
120
|
+
- TODO
|
120
121
|
- bin/couchup
|
121
122
|
- couchup.gemspec
|
122
123
|
- lib/couchup.rb
|
124
|
+
- lib/couchup/commands/compact.rb
|
123
125
|
- lib/couchup/commands/connect.rb
|
124
126
|
- lib/couchup/commands/create.rb
|
127
|
+
- lib/couchup/commands/drop.rb
|
125
128
|
- lib/couchup/commands/get.rb
|
126
129
|
- lib/couchup/commands/help.rb
|
127
130
|
- lib/couchup/commands/map.rb
|
131
|
+
- lib/couchup/commands/replicate_to.rb
|
128
132
|
- lib/couchup/commands/restart.rb
|
129
133
|
- lib/couchup/commands/show.rb
|
130
134
|
- lib/couchup/commands/use.rb
|
@@ -135,6 +139,7 @@ files:
|
|
135
139
|
- lib/couchup/extensions/symbol.rb
|
136
140
|
- lib/couchup/mapreduce.rb
|
137
141
|
- lib/couchup/version.rb
|
142
|
+
- lib/couchup/view.rb
|
138
143
|
has_rdoc: true
|
139
144
|
homepage: ""
|
140
145
|
licenses: []
|