couchup 0.0.1

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.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm ruby-1.9.2@couchup --create
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source :rubygems
2
+ gem 'couchrest'
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,8 @@
1
+ Couchup
2
+ ========
3
+
4
+ This is a command line interface to CouchDb.
5
+
6
+ I plan to gemify it, but currently you should just bundle install and run bin/couchup
7
+
8
+ The irb command line opens up and you can type help to list the commands.
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby
2
+ begin
3
+ require "rubygems"
4
+ require "bundler"
5
+ rescue LoadError
6
+ raise "Could not load the bundler gem. Install it with `gem install bundler`."
7
+ end
8
+
9
+ if Gem::Version.new(Bundler::VERSION) <= Gem::Version.new("0.9.24")
10
+ raise RuntimeError, "Your bundler version is too old for Rails 2.3." +
11
+ "Run `gem install bundler` to upgrade."
12
+ end
13
+
14
+ begin
15
+ # Set up load paths for all bundled gems
16
+ ENV["BUNDLE_GEMFILE"] = File.expand_path("../../Gemfile", __FILE__)
17
+ Bundler.setup
18
+ rescue Bundler::GemNotFound
19
+ raise RuntimeError, "Bundler couldn't find some gems." +
20
+ "Did you run `bundle install`?"
21
+ end
22
+
23
+ Bundler.require :default
24
+ require File.expand_path( "../../lib/couchup", __FILE__)
25
+ require 'irb'
26
+ require 'irb/completion'
27
+
28
+ if File.exists? ".irbrc"
29
+ ENV['IRBRC'] = ".irbrc"
30
+ end
31
+
32
+ if File.exists?( File.expand_path(rcfile = "~/.couchuprc") )
33
+ load(rcfile)
34
+ end
35
+
36
+ ARGV.clear
37
+
38
+ IRB.start
39
+ exit!
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "couchup/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "couchup"
7
+ s.version = Couchup::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["V Sreekanth"]
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.}
14
+
15
+ s.rubyforge_project = "couchup"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
@@ -0,0 +1,17 @@
1
+ require File.expand_path '../couchup/couchup', __FILE__
2
+ Dir[File.expand_path('../couchup/commands/*.rb',__FILE__)].each { |file| require file}
3
+ Dir[File.expand_path('../couchup/extensions/*.rb',__FILE__)].each { |file| require file}
4
+
5
+
6
+ Commands.constants.each do |c|
7
+ instance_eval "
8
+ def #{c.underscore}(*args)
9
+ instance = Commands.const_get(:#{c}).new
10
+ instance.run(*args)
11
+ end"
12
+ end
13
+
14
+ puts "Type help to view the list of things you can do. And Yeah Relax."
15
+
16
+
17
+
@@ -0,0 +1,16 @@
1
+ module Commands
2
+ class Connect
3
+ def run(host = 'localhost', port = 5984)
4
+ Couchup.host = host
5
+ Couchup.port = port
6
+ if(Couchup.ready?)
7
+ puts "Connected to #{Couchup.host}:#{Couchup.port}"
8
+ else
9
+ puts "Could not connect to #{Couchup.host}:#{Couchup.port}"
10
+ end
11
+ end
12
+ def self.describe
13
+ "Connects to the couch server. Takes host and port defaults to 5984"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,11 @@
1
+ module Commands
2
+ class Get
3
+ def run(id = nil)
4
+ id.nil? ? Couchup.all : Couchup.get(id)
5
+ end
6
+
7
+ def self.describe
8
+ "get [id] retuns the document with the id"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ module Commands
2
+ class Help
3
+ def run(option={})
4
+ Commands.constants.each do |stuff|
5
+ k = Commands.const_get(stuff)
6
+ print stuff.downcase; print "\t\t"
7
+ puts k.respond_to?(:describe) ? k.describe : "No Help"
8
+ end
9
+ end
10
+
11
+ def self.describe
12
+ "Help on the system, 'help put' will provider help about put."
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ module Commands
2
+ class Show
3
+
4
+ def run(param = "databases")
5
+ puts Couchup.databases.inspect
6
+ end
7
+ def self.describe
8
+ "show databases"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ module Commands
2
+ class Use
3
+ def run(database)
4
+
5
+ if Couchup.databases.include? database
6
+ Couchup.database = database
7
+ else
8
+ puts "Database was not found"
9
+ end
10
+ end
11
+
12
+ def self.describe
13
+ "Use provided database"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,40 @@
1
+ class Couchup
2
+ class << self
3
+ attr_accessor :port, :host
4
+ def server
5
+ @server ||= CouchRest::Server.new("http://#{host}:#{port}")
6
+ end
7
+
8
+ def database=(database)
9
+ @db = CouchRest.database!("http://#{host}:#{port}/#{database}")
10
+ end
11
+
12
+ def database
13
+ @db.name
14
+ end
15
+
16
+ def ready?
17
+ uuid = nil
18
+ begin
19
+ uuid = server.next_uuid
20
+ rescue
21
+ puts $!.backtrace
22
+ puts $!.inspect
23
+ end
24
+ !uuid.nil?
25
+ end
26
+
27
+ def get(id)
28
+ @db.get(id)
29
+ end
30
+
31
+ def all(options={})
32
+ @db.documents
33
+ end
34
+
35
+ def databases
36
+ server.databases
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,16 @@
1
+ class Symbol
2
+ def constantize
3
+ Object.const_get(to_s)
4
+ end
5
+
6
+ # cargo culted from rails inflector.
7
+ def underscore
8
+ word = to_s.dup
9
+ word.gsub!(/::/, '/')
10
+ word.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
11
+ word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
12
+ word.tr!("-", "_")
13
+ word.downcase!
14
+ word
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module Couchup
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: couchup
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - V Sreekanth
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-02-22 00:00:00 +05:30
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description: Command line inteface to a couchdb deployment.
18
+ email:
19
+ - sreeix@gmail.com
20
+ executables:
21
+ - couchup
22
+ extensions: []
23
+
24
+ extra_rdoc_files: []
25
+
26
+ files:
27
+ - .gitignore
28
+ - .rvmrc
29
+ - Gemfile
30
+ - Gemfile.lock
31
+ - Rakefile
32
+ - Readme.markdown
33
+ - bin/couchup
34
+ - couchup.gemspec
35
+ - lib/couchup.rb
36
+ - lib/couchup/commands/connect.rb
37
+ - lib/couchup/commands/get.rb
38
+ - lib/couchup/commands/help.rb
39
+ - lib/couchup/commands/show.rb
40
+ - lib/couchup/commands/use.rb
41
+ - lib/couchup/couchup.rb
42
+ - lib/couchup/extensions/symbol.rb
43
+ - lib/couchup/version.rb
44
+ has_rdoc: true
45
+ homepage: ""
46
+ licenses: []
47
+
48
+ post_install_message:
49
+ rdoc_options: []
50
+
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: "0"
65
+ requirements: []
66
+
67
+ rubyforge_project: couchup
68
+ rubygems_version: 1.5.2
69
+ signing_key:
70
+ specification_version: 3
71
+ summary: Command line inteface to a couchdb deployment.
72
+ test_files: []
73
+