couchpack 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.5.2"
12
+ gem "rcov", ">= 0"
13
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,20 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.5.2)
6
+ bundler (~> 1.0.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ rake (0.8.7)
10
+ rcov (0.9.9)
11
+ shoulda (2.11.3)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ bundler (~> 1.0.0)
18
+ jeweler (~> 1.5.2)
19
+ rcov
20
+ shoulda
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Stephane Bellity and Kevin Malakoff
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,29 @@
1
+ = couchpack
2
+
3
+ This gem is a tools to help packing couch documents for mobile devices. See https://github.com/kmalakoff/phonegap-couchbase-xplatform for an example use.
4
+
5
+ Install:
6
+ gem install couchpack
7
+
8
+ Usage:
9
+ couchpack [-h <hostname>] [-p <port>] [-d <database>] [-a <document>] [-o <outfile filename>]
10
+
11
+ What it does is strip out the "_id" and "_rev" fields so the document can be uploaded in place without being modified and generates a {document}.JSON file.
12
+
13
+ It also strips out the "_rev" field and puts it in a {document}.VERSION file which can be used to check for modifications to avoid reloading unmodified documents on the target mobile device.
14
+
15
+
16
+ == Contributing to couchpack
17
+
18
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
19
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
20
+ * Fork the project
21
+ * Start a feature/bugfix branch
22
+ * Commit and push until you are happy with your contribution
23
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
24
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
25
+
26
+ == Copyright
27
+
28
+ Copyright (c) 2011 Stephane Bellity and Kevin Malakoff. See LICENSE.txt for further details.
29
+
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'jeweler'
13
+ Jeweler::Tasks.new do |gem|
14
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
15
+ gem.name = "couchpack"
16
+ gem.homepage = "http://github.com/kmalakoff/couchpack-gem"
17
+ gem.license = "MIT"
18
+ gem.summary = %Q{Couch document packing utility}
19
+ gem.description = %Q{Couch document packing utility}
20
+ gem.email = "xmann.intl@gmail.com"
21
+ gem.authors = ["Stephane Bellity", "Kevin Malakoff"]
22
+ # Include your dependencies below. Runtime dependencies are required when using your gem,
23
+ # and development dependencies are only needed for development (ie running rake tasks, tests, etc)
24
+ gem.add_runtime_dependency 'json', '> 1.1.5'
25
+ # gem.add_development_dependency 'rspec', '> 1.2.3'
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+ require 'rake/testtask'
30
+ Rake::TestTask.new(:test) do |test|
31
+ test.libs << 'lib' << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+
36
+ require 'rcov/rcovtask'
37
+ Rcov::RcovTask.new do |test|
38
+ test.libs << 'test'
39
+ test.pattern = 'test/**/test_*.rb'
40
+ test.verbose = true
41
+ end
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "couchpack #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/bin/couchpack ADDED
@@ -0,0 +1,99 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "rubygems"
4
+ require 'optparse'
5
+ require "json"
6
+ require "fileutils"
7
+
8
+
9
+ begin
10
+ # Save ARGV in case someone wants to use it later
11
+ ORIGINAL_ARGV = ARGV.dup
12
+
13
+ options = {:hostname => "localhost", :port => 5984, :db => "couchapp"}
14
+
15
+ opts = OptionParser.new do |opts|
16
+ opts.banner = <<-EOF
17
+ Usage:
18
+ Starting:
19
+ couchpack [-h <hostname>] [-p <port>] [-d <database>] [-a <document>] [-o <outfile filename>]
20
+
21
+ Options:
22
+ EOF
23
+
24
+
25
+ opts.on("-hHOSTNAME", "--hostname HOSTNAME", "Hostname of the CouchDB server") do |x|
26
+ options[:hostname] = x
27
+ end
28
+
29
+ opts.on("-pPORT", "--port PORT", "Port of the CouchDB server") do |x|
30
+ options[:port] = x
31
+ end
32
+
33
+ opts.on("-dDB", "--database DB", "Couch document database name on the CouchDB server") do |x|
34
+ options[:db] = x
35
+ end
36
+
37
+ opts.on("-aDOC", "--adocument DOC", "Couch document name on the CouchDB server") do |x|
38
+ options[:doc] = x
39
+ end
40
+
41
+ opts.on("-oOUTFILE", "--outfile OUTFILE", "Path of the output file") do |x|
42
+ options[:outfile] = x
43
+ end
44
+
45
+ end
46
+
47
+ opts.parse!
48
+
49
+ puts "CouchPack options: #{options.inspect}"
50
+
51
+ rescue => err
52
+
53
+ end
54
+
55
+ # default is using the database name for the document
56
+ if options[:doc].nil?
57
+ options[:doc] = options[:db]
58
+ end
59
+
60
+ # default is using the document name for the output file
61
+ if options[:outfile].nil?
62
+ options[:outfile] = options[:db]
63
+ end
64
+ options[:outfile] = options[:outfile].gsub("//", "")
65
+
66
+ tmp_file = "/tmp/couchpack-#{options[:db]}-#{Time.now.to_i}.json"
67
+ cmd = "curl -o #{tmp_file} \"http://#{options[:hostname]}:#{options[:port]}/#{options[:db]}/#{options[:doc]}?attachments=true\""
68
+
69
+ puts "CMD : #{cmd}"
70
+
71
+ `#{cmd}`
72
+
73
+ json = JSON.parse(open(tmp_file).read)
74
+
75
+ error = json["error"]
76
+
77
+ # success
78
+ if error.nil?
79
+ version = json["_rev"]
80
+
81
+ json.delete("_rev")
82
+ json.delete("_id")
83
+
84
+ f = open(options[:outfile] + ".json", "w")
85
+ f.write(json.to_json)
86
+ f.close
87
+
88
+ f = open(options[:outfile] + ".version", "w")
89
+ f.write(version)
90
+ f.close
91
+
92
+ puts "Success: created bundled document: #{options[:outfile]}.json and version file: #{options[:outfile]}.version."
93
+ puts "Don't forget to add them as a resource to your project!"
94
+ # failure
95
+ else
96
+ puts "Failed: couch responded with: #{json.inspect}"
97
+ end
98
+
99
+ FileUtils.rm(tmp_file)
data/couchpack.gemspec ADDED
@@ -0,0 +1,69 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{couchpack}
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 = ["Stephane Bellity", "Kevin Malakoff"]
12
+ s.date = %q{2011-06-15}
13
+ s.default_executable = %q{couchpack}
14
+ s.description = %q{Couch document packing utility}
15
+ s.email = %q{xmann.intl@gmail.com}
16
+ s.executables = ["couchpack"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.txt",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "bin/couchpack",
30
+ "couchpack.gemspec",
31
+ "lib/couchpack.rb",
32
+ "test/helper.rb",
33
+ "test/test_couchpack.rb"
34
+ ]
35
+ s.homepage = %q{http://github.com/kmalakoff/couchpack-gem}
36
+ s.licenses = ["MIT"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.5.2}
39
+ s.summary = %q{Couch document packing utility}
40
+ s.test_files = [
41
+ "test/helper.rb",
42
+ "test/test_couchpack.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ s.specification_version = 3
47
+
48
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
49
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
50
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
51
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
52
+ s.add_development_dependency(%q<rcov>, [">= 0"])
53
+ s.add_runtime_dependency(%q<json>, ["> 1.1.5"])
54
+ else
55
+ s.add_dependency(%q<shoulda>, [">= 0"])
56
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
57
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
58
+ s.add_dependency(%q<rcov>, [">= 0"])
59
+ s.add_dependency(%q<json>, ["> 1.1.5"])
60
+ end
61
+ else
62
+ s.add_dependency(%q<shoulda>, [">= 0"])
63
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
64
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
65
+ s.add_dependency(%q<rcov>, [">= 0"])
66
+ s.add_dependency(%q<json>, ["> 1.1.5"])
67
+ end
68
+ end
69
+
data/lib/couchpack.rb ADDED
File without changes
data/test/helper.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts "Run `bundle install` to install missing gems"
8
+ exit e.status_code
9
+ end
10
+ require 'test/unit'
11
+ require 'shoulda'
12
+
13
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
14
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
15
+ require 'couchpack'
16
+
17
+ class Test::Unit::TestCase
18
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestCouchPack < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: couchpack
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Stephane Bellity
14
+ - Kevin Malakoff
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2011-06-15 00:00:00 +02:00
20
+ default_executable: couchpack
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ type: :development
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
+ name: shoulda
34
+ version_requirements: *id001
35
+ prerelease: false
36
+ - !ruby/object:Gem::Dependency
37
+ type: :development
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ hash: 23
44
+ segments:
45
+ - 1
46
+ - 0
47
+ - 0
48
+ version: 1.0.0
49
+ name: bundler
50
+ version_requirements: *id002
51
+ prerelease: false
52
+ - !ruby/object:Gem::Dependency
53
+ type: :development
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ hash: 7
60
+ segments:
61
+ - 1
62
+ - 5
63
+ - 2
64
+ version: 1.5.2
65
+ name: jeweler
66
+ version_requirements: *id003
67
+ prerelease: false
68
+ - !ruby/object:Gem::Dependency
69
+ type: :development
70
+ requirement: &id004 !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ name: rcov
80
+ version_requirements: *id004
81
+ prerelease: false
82
+ - !ruby/object:Gem::Dependency
83
+ type: :runtime
84
+ requirement: &id005 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ">"
88
+ - !ruby/object:Gem::Version
89
+ hash: 25
90
+ segments:
91
+ - 1
92
+ - 1
93
+ - 5
94
+ version: 1.1.5
95
+ name: json
96
+ version_requirements: *id005
97
+ prerelease: false
98
+ description: Couch document packing utility
99
+ email: xmann.intl@gmail.com
100
+ executables:
101
+ - couchpack
102
+ extensions: []
103
+
104
+ extra_rdoc_files:
105
+ - LICENSE.txt
106
+ - README.rdoc
107
+ files:
108
+ - .document
109
+ - Gemfile
110
+ - Gemfile.lock
111
+ - LICENSE.txt
112
+ - README.rdoc
113
+ - Rakefile
114
+ - VERSION
115
+ - bin/couchpack
116
+ - couchpack.gemspec
117
+ - lib/couchpack.rb
118
+ - test/helper.rb
119
+ - test/test_couchpack.rb
120
+ has_rdoc: true
121
+ homepage: http://github.com/kmalakoff/couchpack-gem
122
+ licenses:
123
+ - MIT
124
+ post_install_message:
125
+ rdoc_options: []
126
+
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ none: false
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ hash: 3
135
+ segments:
136
+ - 0
137
+ version: "0"
138
+ required_rubygems_version: !ruby/object:Gem::Requirement
139
+ none: false
140
+ requirements:
141
+ - - ">="
142
+ - !ruby/object:Gem::Version
143
+ hash: 3
144
+ segments:
145
+ - 0
146
+ version: "0"
147
+ requirements: []
148
+
149
+ rubyforge_project:
150
+ rubygems_version: 1.5.2
151
+ signing_key:
152
+ specification_version: 3
153
+ summary: Couch document packing utility
154
+ test_files:
155
+ - test/helper.rb
156
+ - test/test_couchpack.rb