couchup 0.0.12 → 0.0.13

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.
data/Gemfile CHANGED
@@ -1,3 +1,4 @@
1
1
  source :rubygems
2
2
  gem 'couchrest'
3
+ gem 'awesome_print'
3
4
  gem 'yajl-ruby'
data/Readme.markdown CHANGED
@@ -63,6 +63,18 @@ To use a specific database switch with.
63
63
  Most Couchup commands need you to be on a specific database.
64
64
 
65
65
 
66
+ Shortcuts
67
+ ----------
68
+
69
+ last_result or __ are short hands to the last result returned by couch operations. These are typically json document( or array of documents)
70
+ Most commands that are in the form of <operation> <:view|| :database || :doc> have short hands like <operation>_<view> or <operation>_database
71
+
72
+ eg. *create_database :foo* is same as *create :database, :foo*
73
+
74
+ or *create_view 'Rider/test'* is the same as *create :view, 'Rider/test'*
75
+
76
+
77
+
66
78
  # Getting documents
67
79
  --------------------
68
80
 
@@ -120,6 +132,20 @@ Will pop a textmate/emacs/vi window with some templates. If the view exists it w
120
132
 
121
133
  To cancel creation of the view, just empty the contents of the file and save.
122
134
 
135
+ # Modifying Documents
136
+ -----------------------
137
+
138
+ We use the last_result that is described in the Basics section, and leverage ruby to do the save.
139
+
140
+ get("<id>")
141
+ last_result[:number] = 100
142
+ last_result.save
143
+
144
+
145
+ You could do this with the view results as well.
146
+
147
+
148
+
123
149
 
124
150
 
125
151
 
data/TODO CHANGED
@@ -1,3 +1,5 @@
1
- Replication
1
+ Pretty print
2
+ Paging
3
+ Decent Editor -> https://github.com/jberkel/interactive_editor
2
4
  Conflicts
3
- Attachments
5
+ Attachments
data/bin/couchup CHANGED
@@ -41,7 +41,7 @@ port = options[:port] || "5984"
41
41
  Couchup::Commands::Connect.new.run(host, port)
42
42
  Couchup::Commands::Use.new.run(options[:db]) unless options[:db].nil?
43
43
  Couchup.debug = true if options[:bug]
44
- puts "Type help to view the list of things you can do. And Yeah Relax."
44
+ ap "Type help to view the list of things you can do. And Yeah Relax."
45
45
 
46
46
  ARGV.clear
47
47
 
data/couchup.gemspec CHANGED
@@ -8,16 +8,16 @@ Gem::Specification.new do |s|
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["V Sreekanth"]
10
10
  s.email = ["sreeix@gmail.com"]
11
- s.homepage = ""
12
- s.summary = %q{Command line inteface to a couchdb deployment.}
13
- s.description = %q{Command line inteface to a couchdb deployment.}
11
+ s.homepage = "http://blog.activesphere.com/introducing-couchup-an-interactive-couchdb-co"
12
+ s.summary = %q{Command line interface to a couchdb deployment.}
13
+ s.description = %q{Command line interface to a couchdb deployment.}
14
14
 
15
15
  s.rubyforge_project = "couchup"
16
16
 
17
17
  s.files = `git ls-files`.split("\n")
18
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
- s.default_executable = "ey"
20
+ s.default_executable = "couchup"
21
21
 
22
22
  s.require_paths = ["lib"]
23
23
 
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
27
27
  s.add_dependency('json')
28
28
  s.add_dependency('mime-types')
29
29
  s.add_dependency('rest-client')
30
+ s.add_dependency('awesome_print')
30
31
 
31
32
  s.add_development_dependency('rspec', '1.3.0')
32
33
  s.add_development_dependency('rake')
data/lib/couchup.rb CHANGED
@@ -1,5 +1,12 @@
1
1
  # require 'yajl-ruby'
2
2
  require 'couchrest'
3
+ begin
4
+ require 'ap'
5
+ rescue LoadError
6
+ puts "'gem install awesome_print' for nicer formatting"
7
+ alias ap puts
8
+ end
9
+
3
10
  require File.expand_path '../couchup/couchup', __FILE__
4
11
  Dir[File.expand_path('../couchup/commands/*.rb',__FILE__)].each { |file| require file}
5
12
  Dir[File.expand_path('../couchup/extensions/*.rb',__FILE__)].each { |file| require file}
@@ -8,13 +15,19 @@ Dir[File.expand_path('../couchup/*.rb',__FILE__)].each { |file| require file}
8
15
 
9
16
  Couchup::Commands.constants.each do |c|
10
17
  instance_eval "
18
+ def last_result
19
+ Couchup::Couchup.last_result
20
+ end
21
+ alias __ last_result
11
22
  def #{c.underscore}(*args)
12
23
  begin
13
24
  instance = Couchup::Commands.const_get(:#{c}).new
14
- instance.run(*args)
25
+ Couchup::Couchup.last_result = instance.run(*args)
26
+ nil
15
27
  rescue
16
- puts $!.inspect
17
- puts $!.backtrace if Couchup.debug?
28
+ puts $!.class
29
+ ap $!.inspect
30
+ ap $!.backtrace if Couchup::Couchup.debug?
18
31
  end
19
32
  end"
20
33
  end
@@ -5,9 +5,9 @@ module Couchup
5
5
  Couchup.host = host
6
6
  Couchup.port = port
7
7
  if(Couchup.ready?)
8
- puts "Connected to #{Couchup.host}:#{Couchup.port}"
8
+ ap "Connected to #{Couchup.host}:#{Couchup.port}"
9
9
  else
10
- puts "Could not connect to #{Couchup.host}:#{Couchup.port}"
10
+ ap "Could not connect to #{Couchup.host}:#{Couchup.port}"
11
11
  end
12
12
  end
13
13
  def self.describe
@@ -2,7 +2,9 @@ module Couchup
2
2
  module Commands
3
3
  class Get
4
4
  def run(id = nil)
5
- id.nil? ? Couchup.all : Couchup.get(id)
5
+ match = id.nil? ? Couchup.all.collect{|c| c["doc"]} : Couchup.get(id)
6
+ ap match
7
+ match
6
8
  end
7
9
 
8
10
  def self.describe
@@ -7,7 +7,7 @@ module Couchup
7
7
  k = Commands.const_get(stuff)
8
8
  print stuff.underscore
9
9
  print (stuff.underscore.size > 10) ? "\t" : "\t\t"
10
- puts k.respond_to?(:describe) ? k.describe : "No Help"
10
+ ap k.respond_to?(:describe) ? k.describe : "No Help"
11
11
  end
12
12
  end
13
13
 
@@ -3,7 +3,8 @@ module Couchup
3
3
  class Map
4
4
  def run(*params)
5
5
  rows = MapReduce.map(*params)
6
- puts "Found #{rows.size} item(s)"
6
+ ap "Found #{rows.size} item(s)"
7
+ ap rows
7
8
  rows
8
9
  end
9
10
 
@@ -4,9 +4,9 @@ module Couchup
4
4
  def run(*param)
5
5
  option = param.first.to_s
6
6
  if(option.blank? || option == 'databases' )
7
- puts Couchup.databases.inspect
7
+ ap Couchup.databases
8
8
  else
9
- puts Couchup.views(param.second).inspect
9
+ ap Couchup.views(param.second)
10
10
  end
11
11
  end
12
12
 
@@ -5,9 +5,9 @@ module Couchup
5
5
  db = database.to_s
6
6
  if Couchup.databases.include? db
7
7
  Couchup.database = db
8
- puts Couchup.database.info.inspect
8
+ ap Couchup.database.info
9
9
  else
10
- puts "Database was not found"
10
+ ap "Database was not found"
11
11
  end
12
12
  end
13
13
 
@@ -3,9 +3,9 @@ module Couchup
3
3
  class View
4
4
  def run(*params)
5
5
  rows = MapReduce.reduce(*params)
6
- puts "Found #{rows.size} item(s)"
7
- rows.each{|r| puts r.inspect}
8
- nil
6
+ ap "Found #{rows.size} item(s)"
7
+ ap rows
8
+ rows
9
9
  end
10
10
 
11
11
  def self.describe(params = nil)
@@ -2,6 +2,7 @@ module Couchup
2
2
  class Couchup
3
3
  class << self
4
4
  attr_accessor :port, :host
5
+ attr_accessor :last_result
5
6
  def server
6
7
  @server ||= CouchRest::Server.new("http://#{host}:#{port}")
7
8
  end
@@ -18,15 +19,20 @@ module Couchup
18
19
  params = design.nil? ? {:startkey => '_design', :endkey => '_design0'} : {:key => "_design\\#{design}"}
19
20
  designs = database.documents(params.merge(:include_docs => true))["rows"]
20
21
  designs.collect do |d|
21
- d["doc"]["views"].keys.collect{|view| "#{d['key'].gsub('_design/','')}/#{view}"}
22
+ d["doc"]["views"].keys.collect do |view|
23
+ map = !d["doc"]["views"][view]["map"].blank?
24
+ reduce = !d["doc"]["views"][view]["reduce"].blank?
25
+ {"#{d['key'].gsub('_design/','')}/#{view}" => {:reduce => reduce, :map => map}}
26
+ end
22
27
  end.flatten
23
28
  end
29
+
24
30
  def delete_doc(id)
25
31
  doc = database.get(id)
26
32
  database.delete_doc(doc)
27
33
  end
28
34
  def delete_all_docs(view_name)
29
- all_docs = view_name.nil? ? all(:include_docs => true)["rows"] : MapReduce.map(view_name)
35
+ all_docs = view_name.nil? ? all : MapReduce.map(view_name)
30
36
  all_docs.collect{|d| d["doc"]}.each do |doc|
31
37
  database.delete_doc(doc) unless (doc["_id"] =~ /^_design/)
32
38
  end
@@ -35,10 +41,11 @@ module Couchup
35
41
  def ready?
36
42
  uuid = nil
37
43
  begin
38
- puts (info = server.info)
44
+ ap (info = server.info)
39
45
  rescue
40
- puts $!.backtrace
41
- puts $!.inspect
46
+ ap $!.inspect
47
+ ap $!.backtrace if debug?
48
+
42
49
  end
43
50
  !info.nil?
44
51
  end
@@ -48,8 +55,9 @@ module Couchup
48
55
  end
49
56
 
50
57
  def all(options={})
51
- @db.documents(options)
58
+ @db.documents(options.merge(:include_docs => true))["rows"]
52
59
  end
60
+
53
61
  def debug=(value)
54
62
  @debug = value
55
63
  end
@@ -3,10 +3,19 @@ module Couchup
3
3
  def self.map(*params)
4
4
  #FIXME. should probably get view meta data to do one view call. but this is also doing 2 calls.
5
5
  begin
6
- view({}, *params)
6
+ response = view({:include_docs => true}, *params)
7
7
  rescue RestClient::BadRequest
8
- view({:reduce => false}, *params)
8
+ response = view({:reduce => false, :include_docs => true}, *params)
9
9
  end
10
+
11
+ docs = response["rows"].collect do |r|
12
+ r["doc"].instance_eval "def save
13
+ ::Couchup::Couchup.database.save_doc(self)
14
+ end
15
+ "
16
+ r["doc"]
17
+ end
18
+
10
19
  end
11
20
 
12
21
  def self.reduce(*params)
@@ -16,7 +25,7 @@ module Couchup
16
25
  private
17
26
  def self.view(options, *params)
18
27
  name = params.shift
19
- view_params = {:include_docs => true}.merge(options)
28
+ view_params = options
20
29
  if params.size == 1
21
30
  val = params.first
22
31
  if val.is_a? Array
@@ -28,7 +37,6 @@ module Couchup
28
37
  end
29
38
  end
30
39
  response = Couchup.database.view(name, view_params)
31
- rows = response["rows"]
32
40
  end
33
41
  end
34
42
  end
@@ -1,3 +1,3 @@
1
1
  module Couchup
2
- VERSION = "0.0.12"
2
+ VERSION = "0.0.13"
3
3
  end
data/lib/couchup/view.rb CHANGED
@@ -8,7 +8,7 @@ module Couchup
8
8
  begin
9
9
  @doc = Couchup.database.get("_design/#{@design}")
10
10
  rescue
11
- puts "Design #{@design} not found creating a new one"
11
+ ap "Design #{@design} not found creating a new one"
12
12
  @doc = {"_id" => "_design/#{@design}", :language => 'javascript', :views => {}}
13
13
  save
14
14
  @doc = Couchup.database.get("_design/#{@design}")
@@ -63,7 +63,7 @@ module Couchup
63
63
  map, reduce = parse(file_contents)
64
64
  v.map = map
65
65
  v.reduce = reduce unless reduce.blank?
66
- puts v.inspect
66
+ ap v
67
67
  v.save
68
68
  end
69
69
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: couchup
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.12
5
+ version: 0.0.13
6
6
  platform: ruby
7
7
  authors:
8
8
  - V Sreekanth
@@ -10,8 +10,8 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-02-28 00:00:00 +05:30
14
- default_executable: ey
13
+ date: 2011-03-01 00:00:00 +05:30
14
+ default_executable: couchup
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: couchrest
@@ -69,39 +69,50 @@ dependencies:
69
69
  type: :runtime
70
70
  version_requirements: *id005
71
71
  - !ruby/object:Gem::Dependency
72
- name: rspec
72
+ name: awesome_print
73
73
  prerelease: false
74
74
  requirement: &id006 !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: "0"
80
+ type: :runtime
81
+ version_requirements: *id006
82
+ - !ruby/object:Gem::Dependency
83
+ name: rspec
84
+ prerelease: false
85
+ requirement: &id007 !ruby/object:Gem::Requirement
75
86
  none: false
76
87
  requirements:
77
88
  - - "="
78
89
  - !ruby/object:Gem::Version
79
90
  version: 1.3.0
80
91
  type: :development
81
- version_requirements: *id006
92
+ version_requirements: *id007
82
93
  - !ruby/object:Gem::Dependency
83
94
  name: rake
84
95
  prerelease: false
85
- requirement: &id007 !ruby/object:Gem::Requirement
96
+ requirement: &id008 !ruby/object:Gem::Requirement
86
97
  none: false
87
98
  requirements:
88
99
  - - ">="
89
100
  - !ruby/object:Gem::Version
90
101
  version: "0"
91
102
  type: :development
92
- version_requirements: *id007
103
+ version_requirements: *id008
93
104
  - !ruby/object:Gem::Dependency
94
105
  name: bundler
95
106
  prerelease: false
96
- requirement: &id008 !ruby/object:Gem::Requirement
107
+ requirement: &id009 !ruby/object:Gem::Requirement
97
108
  none: false
98
109
  requirements:
99
110
  - - ">="
100
111
  - !ruby/object:Gem::Version
101
112
  version: "0"
102
113
  type: :development
103
- version_requirements: *id008
104
- description: Command line inteface to a couchdb deployment.
114
+ version_requirements: *id009
115
+ description: Command line interface to a couchdb deployment.
105
116
  email:
106
117
  - sreeix@gmail.com
107
118
  executables:
@@ -142,7 +153,7 @@ files:
142
153
  - lib/couchup/version.rb
143
154
  - lib/couchup/view.rb
144
155
  has_rdoc: true
145
- homepage: ""
156
+ homepage: http://blog.activesphere.com/introducing-couchup-an-interactive-couchdb-co
146
157
  licenses: []
147
158
 
148
159
  post_install_message:
@@ -165,9 +176,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
176
  requirements: []
166
177
 
167
178
  rubyforge_project: couchup
168
- rubygems_version: 1.5.2
179
+ rubygems_version: 1.5.3
169
180
  signing_key:
170
181
  specification_version: 3
171
- summary: Command line inteface to a couchdb deployment.
182
+ summary: Command line interface to a couchdb deployment.
172
183
  test_files: []
173
184