juozasg-couchrest 0.10.1 → 0.10.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.
- metadata +6 -101
- data/Rakefile +0 -86
- data/bin/couchapp +0 -58
- data/bin/couchdir +0 -20
- data/bin/couchview +0 -48
- data/examples/model/example.rb +0 -138
- data/examples/word_count/markov +0 -38
- data/examples/word_count/views/books/chunked-map.js +0 -3
- data/examples/word_count/views/books/united-map.js +0 -1
- data/examples/word_count/views/markov/chain-map.js +0 -6
- data/examples/word_count/views/markov/chain-reduce.js +0 -7
- data/examples/word_count/views/word_count/count-map.js +0 -6
- data/examples/word_count/views/word_count/count-reduce.js +0 -3
- data/examples/word_count/word_count.rb +0 -67
- data/examples/word_count/word_count_query.rb +0 -39
- data/lib/couchrest/commands/generate.rb +0 -71
- data/lib/couchrest/commands/push.rb +0 -103
- data/lib/couchrest/core/database.rb +0 -173
- data/lib/couchrest/core/design.rb +0 -89
- data/lib/couchrest/core/document.rb +0 -60
- data/lib/couchrest/core/model.rb +0 -557
- data/lib/couchrest/core/server.rb +0 -51
- data/lib/couchrest/core/view.rb +0 -4
- data/lib/couchrest/helper/file_manager.rb +0 -317
- data/lib/couchrest/helper/pager.rb +0 -103
- data/lib/couchrest/helper/streamer.rb +0 -44
- data/lib/couchrest/helper/templates/bar.txt +0 -11
- data/lib/couchrest/helper/templates/example-map.js +0 -8
- data/lib/couchrest/helper/templates/example-reduce.js +0 -10
- data/lib/couchrest/helper/templates/index.html +0 -26
- data/lib/couchrest/monkeypatches.rb +0 -24
- data/lib/couchrest.rb +0 -125
- data/spec/couchapp_spec.rb +0 -87
- data/spec/couchrest/core/couchrest_spec.rb +0 -191
- data/spec/couchrest/core/database_spec.rb +0 -478
- data/spec/couchrest/core/design_spec.rb +0 -131
- data/spec/couchrest/core/document_spec.rb +0 -96
- data/spec/couchrest/core/model_spec.rb +0 -660
- data/spec/couchrest/helpers/file_manager_spec.rb +0 -203
- data/spec/couchrest/helpers/pager_spec.rb +0 -122
- data/spec/couchrest/helpers/streamer_spec.rb +0 -23
- data/spec/fixtures/attachments/couchdb.png +0 -0
- data/spec/fixtures/attachments/test.html +0 -11
- data/spec/fixtures/views/lib.js +0 -3
- data/spec/fixtures/views/test_view/lib.js +0 -3
- data/spec/fixtures/views/test_view/only-map.js +0 -4
- data/spec/fixtures/views/test_view/test-map.js +0 -3
- data/spec/fixtures/views/test_view/test-reduce.js +0 -3
- data/spec/spec.opts +0 -6
- data/spec/spec_helper.rb +0 -14
- data/utils/remap.rb +0 -27
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: juozasg-couchrest
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.10.
|
|
4
|
+
version: 0.10.13
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- J. Chris Anderson
|
|
@@ -11,40 +11,12 @@ cert_chain: []
|
|
|
11
11
|
|
|
12
12
|
date: 2008-10-27 00:00:00 -07:00
|
|
13
13
|
default_executable:
|
|
14
|
-
dependencies:
|
|
15
|
-
|
|
16
|
-
name: json
|
|
17
|
-
version_requirement:
|
|
18
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
19
|
-
requirements:
|
|
20
|
-
- - ">="
|
|
21
|
-
- !ruby/object:Gem::Version
|
|
22
|
-
version: 1.1.2
|
|
23
|
-
version:
|
|
24
|
-
- !ruby/object:Gem::Dependency
|
|
25
|
-
name: rest-client
|
|
26
|
-
version_requirement:
|
|
27
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
28
|
-
requirements:
|
|
29
|
-
- - ">="
|
|
30
|
-
- !ruby/object:Gem::Version
|
|
31
|
-
version: "0.5"
|
|
32
|
-
version:
|
|
33
|
-
- !ruby/object:Gem::Dependency
|
|
34
|
-
name: extlib
|
|
35
|
-
version_requirement:
|
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
-
requirements:
|
|
38
|
-
- - ">="
|
|
39
|
-
- !ruby/object:Gem::Version
|
|
40
|
-
version: 0.9.6
|
|
41
|
-
version:
|
|
14
|
+
dependencies: []
|
|
15
|
+
|
|
42
16
|
description: CouchRest provides a simple interface on top of CouchDB's RESTful HTTP API, as well as including some utility scripts for managing views and attachments.
|
|
43
17
|
email: jchris@grabb.it
|
|
44
|
-
executables:
|
|
45
|
-
|
|
46
|
-
- couchdir
|
|
47
|
-
- couchapp
|
|
18
|
+
executables: []
|
|
19
|
+
|
|
48
20
|
extensions: []
|
|
49
21
|
|
|
50
22
|
extra_rdoc_files:
|
|
@@ -54,76 +26,9 @@ extra_rdoc_files:
|
|
|
54
26
|
files:
|
|
55
27
|
- LICENSE
|
|
56
28
|
- README.rdoc
|
|
57
|
-
- Rakefile
|
|
58
|
-
- THANKS
|
|
59
|
-
- bin/couchapp
|
|
60
|
-
- bin/couchdir
|
|
61
|
-
- bin/couchview
|
|
62
|
-
- examples/model
|
|
63
|
-
- examples/model/example.rb
|
|
64
|
-
- examples/word_count
|
|
65
|
-
- examples/word_count/markov
|
|
66
|
-
- examples/word_count/views
|
|
67
|
-
- examples/word_count/views/books
|
|
68
|
-
- examples/word_count/views/books/chunked-map.js
|
|
69
|
-
- examples/word_count/views/books/united-map.js
|
|
70
|
-
- examples/word_count/views/markov
|
|
71
|
-
- examples/word_count/views/markov/chain-map.js
|
|
72
|
-
- examples/word_count/views/markov/chain-reduce.js
|
|
73
|
-
- examples/word_count/views/word_count
|
|
74
|
-
- examples/word_count/views/word_count/count-map.js
|
|
75
|
-
- examples/word_count/views/word_count/count-reduce.js
|
|
76
|
-
- examples/word_count/word_count.rb
|
|
77
|
-
- examples/word_count/word_count_query.rb
|
|
78
|
-
- lib/couchrest
|
|
79
|
-
- lib/couchrest/commands
|
|
80
|
-
- lib/couchrest/commands/generate.rb
|
|
81
|
-
- lib/couchrest/commands/push.rb
|
|
82
|
-
- lib/couchrest/core
|
|
83
|
-
- lib/couchrest/core/database.rb
|
|
84
|
-
- lib/couchrest/core/design.rb
|
|
85
|
-
- lib/couchrest/core/document.rb
|
|
86
|
-
- lib/couchrest/core/model.rb
|
|
87
|
-
- lib/couchrest/core/server.rb
|
|
88
|
-
- lib/couchrest/core/view.rb
|
|
89
29
|
- lib/couchrest/helper
|
|
90
|
-
- lib/couchrest/helper/file_manager.rb
|
|
91
|
-
- lib/couchrest/helper/pager.rb
|
|
92
|
-
- lib/couchrest/helper/streamer.rb
|
|
93
|
-
- lib/couchrest/helper/templates
|
|
94
|
-
- lib/couchrest/helper/templates/bar.txt
|
|
95
|
-
- lib/couchrest/helper/templates/example-map.js
|
|
96
|
-
- lib/couchrest/helper/templates/example-reduce.js
|
|
97
|
-
- lib/couchrest/helper/templates/index.html
|
|
98
|
-
- lib/couchrest/monkeypatches.rb
|
|
99
|
-
- lib/couchrest.rb
|
|
100
|
-
- spec/couchapp_spec.rb
|
|
101
|
-
- spec/couchrest
|
|
102
|
-
- spec/couchrest/core
|
|
103
|
-
- spec/couchrest/core/couchrest_spec.rb
|
|
104
|
-
- spec/couchrest/core/database_spec.rb
|
|
105
|
-
- spec/couchrest/core/design_spec.rb
|
|
106
|
-
- spec/couchrest/core/document_spec.rb
|
|
107
|
-
- spec/couchrest/core/model_spec.rb
|
|
108
|
-
- spec/couchrest/helpers
|
|
109
|
-
- spec/couchrest/helpers/file_manager_spec.rb
|
|
110
|
-
- spec/couchrest/helpers/pager_spec.rb
|
|
111
|
-
- spec/couchrest/helpers/streamer_spec.rb
|
|
112
|
-
- spec/fixtures
|
|
113
|
-
- spec/fixtures/attachments
|
|
114
|
-
- spec/fixtures/attachments/couchdb.png
|
|
115
|
-
- spec/fixtures/attachments/test.html
|
|
116
|
-
- spec/fixtures/views
|
|
117
|
-
- spec/fixtures/views/lib.js
|
|
118
|
-
- spec/fixtures/views/test_view
|
|
119
|
-
- spec/fixtures/views/test_view/lib.js
|
|
120
|
-
- spec/fixtures/views/test_view/only-map.js
|
|
121
|
-
- spec/fixtures/views/test_view/test-map.js
|
|
122
|
-
- spec/fixtures/views/test_view/test-reduce.js
|
|
123
|
-
- spec/spec.opts
|
|
124
|
-
- spec/spec_helper.rb
|
|
125
|
-
- utils/remap.rb
|
|
126
30
|
- utils/subset.rb
|
|
31
|
+
- THANKS
|
|
127
32
|
has_rdoc: "true"
|
|
128
33
|
homepage: http://github.com/jchris/couchrest
|
|
129
34
|
post_install_message:
|
data/Rakefile
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
require 'rake'
|
|
2
|
-
require "rake/rdoctask"
|
|
3
|
-
require 'spec/rake/spectask'
|
|
4
|
-
require 'rake/gempackagetask'
|
|
5
|
-
|
|
6
|
-
spec = Gem::Specification.new do |s|
|
|
7
|
-
s.name = "couchrest"
|
|
8
|
-
s.version = "0.10.1"
|
|
9
|
-
s.date = "2008-11-22"
|
|
10
|
-
s.summary = "Lean and RESTful interface to CouchDB."
|
|
11
|
-
s.email = "jchris@grabb.it"
|
|
12
|
-
s.homepage = "http://github.com/jchris/couchrest"
|
|
13
|
-
s.description = "CouchRest provides a simple interface on top of CouchDB's RESTful HTTP API, as well as including some utility scripts for managing views and attachments."
|
|
14
|
-
s.has_rdoc = true
|
|
15
|
-
s.authors = ["J. Chris Anderson"]
|
|
16
|
-
s.files = %w( LICENSE README.rdoc Rakefile THANKS ) +
|
|
17
|
-
Dir["{bin,examples,lib,spec,utils}/**/*"] -
|
|
18
|
-
Dir["spec/fixtures/couchapp*/**/*"] - Dir["spec/fixtures/couchapp*"]
|
|
19
|
-
s.extra_rdoc_files = %w( README.rdoc LICENSE THANKS )
|
|
20
|
-
s.require_path = "lib"
|
|
21
|
-
s.bindir = 'bin'
|
|
22
|
-
s.executables << 'couchview'
|
|
23
|
-
s.executables << 'couchdir'
|
|
24
|
-
s.executables << 'couchapp'
|
|
25
|
-
s.add_dependency("json", ">= 1.1.2")
|
|
26
|
-
s.add_dependency("rest-client", ">= 0.5")
|
|
27
|
-
s.add_dependency("extlib", ">= 0.9.6")
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
::Rake::GemPackageTask.new(spec) { |p| p.gem_spec = spec }
|
|
31
|
-
|
|
32
|
-
desc "Update Github Gemspec"
|
|
33
|
-
task :gemspec do
|
|
34
|
-
skip_fields = %w(new_platform original_platform)
|
|
35
|
-
integer_fields = %w(specification_version)
|
|
36
|
-
|
|
37
|
-
result = "Gem::Specification.new do |s|\n"
|
|
38
|
-
spec.instance_variables.each do |ivar|
|
|
39
|
-
value = spec.instance_variable_get(ivar)
|
|
40
|
-
name = ivar.split("@").last
|
|
41
|
-
next if skip_fields.include?(name) || value.nil? || value == "" || (value.respond_to?(:empty?) && value.empty?)
|
|
42
|
-
if name == "dependencies"
|
|
43
|
-
value.each do |d|
|
|
44
|
-
dep, *ver = d.to_s.split(" ")
|
|
45
|
-
result << " s.add_dependency #{dep.inspect}, [#{ /\(([^\,]*)/ . match(ver.join(" "))[1].inspect}]\n"
|
|
46
|
-
end
|
|
47
|
-
else
|
|
48
|
-
case value
|
|
49
|
-
when Array
|
|
50
|
-
value = name != "files" ? value.inspect : value.inspect.split(",").join(",\n")
|
|
51
|
-
when Fixnum
|
|
52
|
-
# leave as-is
|
|
53
|
-
when String
|
|
54
|
-
value = value.to_i if integer_fields.include?(name)
|
|
55
|
-
value = value.inspect
|
|
56
|
-
else
|
|
57
|
-
value = value.to_s.inspect
|
|
58
|
-
end
|
|
59
|
-
result << " s.#{name} = #{value}\n"
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
result << "end"
|
|
63
|
-
File.open(File.join(File.dirname(__FILE__), "#{spec.name}.gemspec"), "w"){|f| f << result}
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
desc "Run all specs"
|
|
67
|
-
Spec::Rake::SpecTask.new('spec') do |t|
|
|
68
|
-
t.spec_files = FileList['spec/**/*_spec.rb']
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
desc "Print specdocs"
|
|
72
|
-
Spec::Rake::SpecTask.new(:doc) do |t|
|
|
73
|
-
t.spec_opts = ["--format", "specdoc"]
|
|
74
|
-
t.spec_files = FileList['spec/*_spec.rb']
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
desc "Generate the rdoc"
|
|
78
|
-
Rake::RDocTask.new do |rdoc|
|
|
79
|
-
files = ["README.rdoc", "LICENSE", "lib/**/*.rb"]
|
|
80
|
-
rdoc.rdoc_files.add(files)
|
|
81
|
-
rdoc.main = "README.rdoc"
|
|
82
|
-
rdoc.title = "CouchRest: Ruby CouchDB, close to the metal"
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
desc "Run the rspec"
|
|
86
|
-
task :default => :spec
|
data/bin/couchapp
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
|
|
3
|
-
require 'optparse'
|
|
4
|
-
require File.expand_path(File.dirname(__FILE__)) + '/../lib/couchrest'
|
|
5
|
-
|
|
6
|
-
options = {
|
|
7
|
-
:loud => true,
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
opts = OptionParser.new do |opts|
|
|
11
|
-
opts.banner = "Usage: #$0 [options] (push|pull|generate)"
|
|
12
|
-
opts.on('-q', '--quiet', "Omit extra debug info") do
|
|
13
|
-
options[:loud] = false
|
|
14
|
-
end
|
|
15
|
-
opts.on_tail('-h', '--help', "Display detailed help and exit") do
|
|
16
|
-
puts opts
|
|
17
|
-
exit
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
opts.parse!(ARGV)
|
|
22
|
-
|
|
23
|
-
case ARGV.shift
|
|
24
|
-
when /generate/
|
|
25
|
-
appname = ARGV.shift
|
|
26
|
-
current = Dir.getwd
|
|
27
|
-
appdir = File.join(current, appname)
|
|
28
|
-
puts "generating couchapp in #{appdir}"
|
|
29
|
-
CouchRest::FileManager.generate_app(appdir)
|
|
30
|
-
|
|
31
|
-
when /push/
|
|
32
|
-
dirname = ARGV.shift
|
|
33
|
-
current = Dir.getwd
|
|
34
|
-
dir = File.expand_path(File.join(current, dirname))
|
|
35
|
-
dirapp = File.split(dir).last
|
|
36
|
-
if ARGV.length == 2
|
|
37
|
-
appname = ARGV.shift
|
|
38
|
-
dbstring = ARGV.shift
|
|
39
|
-
elsif ARGV.length == 1
|
|
40
|
-
appname = dirapp
|
|
41
|
-
dbstring = ARGV.shift
|
|
42
|
-
else
|
|
43
|
-
puts opts
|
|
44
|
-
puts "push dirname [appname] database"
|
|
45
|
-
exit(0)
|
|
46
|
-
end
|
|
47
|
-
CouchRest.database!(dbstring)
|
|
48
|
-
dbspec = CouchRest.parse(dbstring)
|
|
49
|
-
fm = CouchRest::FileManager.new(dbspec[:database], dbspec[:host])
|
|
50
|
-
fm.push_app(dir, appname)
|
|
51
|
-
|
|
52
|
-
when /pull/
|
|
53
|
-
puts "pull is not yet implemented"
|
|
54
|
-
|
|
55
|
-
else
|
|
56
|
-
puts opts
|
|
57
|
-
puts "please specify a command"
|
|
58
|
-
end
|
data/bin/couchdir
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
|
|
3
|
-
unless ARGV.length >= 2
|
|
4
|
-
puts "usage: couchdir path/to/directory db-name [docid]"
|
|
5
|
-
exit
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
require 'rubygems'
|
|
9
|
-
require 'couchrest'
|
|
10
|
-
|
|
11
|
-
dirname = ARGV[0]
|
|
12
|
-
dbname = ARGV[1]
|
|
13
|
-
docid = ARGV[2]
|
|
14
|
-
|
|
15
|
-
puts "Create attachments for the files in #{dirname} in database #{dbname}."
|
|
16
|
-
|
|
17
|
-
fm = CouchRest::FileManager.new(dbname)
|
|
18
|
-
fm.loud = true
|
|
19
|
-
puts "Pushing views from directory #{dirname} to database #{fm.db}"
|
|
20
|
-
fm.push_directory(dirname, docid)
|
data/bin/couchview
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
|
|
3
|
-
require 'optparse'
|
|
4
|
-
require 'couchrest'
|
|
5
|
-
|
|
6
|
-
%w(generate push).each do |file|
|
|
7
|
-
require File.dirname(__FILE__) + "/../lib/couchrest/commands/#{file}"
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
# Set defaults
|
|
11
|
-
options = {
|
|
12
|
-
:loud => true,
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
opts = OptionParser.new do |opts|
|
|
16
|
-
opts.banner = "Usage: #$0 [options] (push|generate) directory database"
|
|
17
|
-
opts.on('-q', '--quiet', "Omit extra debug info") do
|
|
18
|
-
options[:loud] = false
|
|
19
|
-
end
|
|
20
|
-
opts.on_tail('-h', '--help [push|generate]', "Display detailed help and exit") do |help_command|
|
|
21
|
-
puts opts
|
|
22
|
-
case help_command
|
|
23
|
-
when "push"
|
|
24
|
-
puts CouchRest::Commands::Push.help
|
|
25
|
-
when "generate"
|
|
26
|
-
puts CouchRest::Commands::Generate.help
|
|
27
|
-
end
|
|
28
|
-
exit
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
opts.parse!(ARGV)
|
|
32
|
-
|
|
33
|
-
options[:command] = ARGV.shift
|
|
34
|
-
options[:directory] = ARGV.shift
|
|
35
|
-
options[:trailing_args] = ARGV
|
|
36
|
-
|
|
37
|
-
# There must be a better way to check for extra required args
|
|
38
|
-
unless (["push", "generate"].include?(options[:command]) && options[:directory] && options[:trailing_args])
|
|
39
|
-
puts(opts)
|
|
40
|
-
exit
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
case options[:command]
|
|
44
|
-
when "push"
|
|
45
|
-
CouchRest::Commands::Push.run(options)
|
|
46
|
-
when "generate"
|
|
47
|
-
CouchRest::Commands::Generate.run(options)
|
|
48
|
-
end
|
data/examples/model/example.rb
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
require 'rubygems'
|
|
2
|
-
require 'couchrest'
|
|
3
|
-
|
|
4
|
-
def show obj
|
|
5
|
-
puts obj.inspect
|
|
6
|
-
puts
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
CouchRest::Model.default_database = CouchRest.database!('couchrest-model-example')
|
|
10
|
-
|
|
11
|
-
class Author < CouchRest::Model
|
|
12
|
-
key_accessor :name
|
|
13
|
-
def drink_scotch
|
|
14
|
-
puts "... glug type glug ... I'm #{name} ... type glug glug ..."
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
class Post < CouchRest::Model
|
|
19
|
-
key_accessor :title, :body, :author
|
|
20
|
-
|
|
21
|
-
cast :author, :as => 'Author'
|
|
22
|
-
|
|
23
|
-
timestamps!
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
class Comment < CouchRest::Model
|
|
27
|
-
cast :commenter, :as => 'Author'
|
|
28
|
-
|
|
29
|
-
def post= post
|
|
30
|
-
self["post_id"] = post.id
|
|
31
|
-
end
|
|
32
|
-
def post
|
|
33
|
-
Post.get(self['post_id']) if self['post_id']
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
timestamps!
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
puts "Act I: CRUD"
|
|
40
|
-
puts
|
|
41
|
-
puts "(pause for dramatic effect)"
|
|
42
|
-
puts
|
|
43
|
-
sleep 2
|
|
44
|
-
|
|
45
|
-
puts "Create an author."
|
|
46
|
-
quentin = Author.new("name" => "Quentin Hazel")
|
|
47
|
-
show quentin
|
|
48
|
-
|
|
49
|
-
puts "Create a new post."
|
|
50
|
-
post = Post.new(:title => "First Post", :body => "Lorem ipsum dolor sit amet, consectetur adipisicing elit...")
|
|
51
|
-
show post
|
|
52
|
-
|
|
53
|
-
puts "Add the author to the post."
|
|
54
|
-
post.author = quentin
|
|
55
|
-
show post
|
|
56
|
-
|
|
57
|
-
puts "Save the post."
|
|
58
|
-
post.save
|
|
59
|
-
show post
|
|
60
|
-
|
|
61
|
-
puts "Load the post."
|
|
62
|
-
reloaded = Post.get(post.id)
|
|
63
|
-
show reloaded
|
|
64
|
-
|
|
65
|
-
puts "The author of the post is an instance of Author."
|
|
66
|
-
reloaded.author.drink_scotch
|
|
67
|
-
|
|
68
|
-
puts "\nAdd some comments to the post."
|
|
69
|
-
comment_one = Comment.new :text => "Blah blah blah", :commenter => {:name => "Joe Sixpack"}
|
|
70
|
-
comment_two = Comment.new :text => "Yeah yeah yeah", :commenter => {:name => "Jane Doe"}
|
|
71
|
-
comment_three = Comment.new :text => "Whatever...", :commenter => {:name => "John Stewart"}
|
|
72
|
-
|
|
73
|
-
# TODO - maybe add some magic here?
|
|
74
|
-
comment_one.post = post
|
|
75
|
-
comment_two.post = post
|
|
76
|
-
comment_three.post = post
|
|
77
|
-
comment_one.save
|
|
78
|
-
comment_two.save
|
|
79
|
-
comment_three.save
|
|
80
|
-
|
|
81
|
-
show comment_one
|
|
82
|
-
show comment_two
|
|
83
|
-
show comment_three
|
|
84
|
-
|
|
85
|
-
puts "We can load a post through its comment (no magic here)."
|
|
86
|
-
show post = comment_one.post
|
|
87
|
-
|
|
88
|
-
puts "Commenters are also authors."
|
|
89
|
-
comment_two['commenter'].drink_scotch
|
|
90
|
-
comment_one['commenter'].drink_scotch
|
|
91
|
-
comment_three['commenter'].drink_scotch
|
|
92
|
-
|
|
93
|
-
puts "\nLet's save an author to her own document."
|
|
94
|
-
jane = comment_two['commenter']
|
|
95
|
-
jane.save
|
|
96
|
-
show jane
|
|
97
|
-
|
|
98
|
-
puts "Oh, that's neat! Because Ruby passes hash valuee by reference, Jane's new id has been added to the comment she left."
|
|
99
|
-
show comment_two
|
|
100
|
-
|
|
101
|
-
puts "Of course, we'd better remember to save it."
|
|
102
|
-
comment_two.save
|
|
103
|
-
show comment_two
|
|
104
|
-
|
|
105
|
-
puts "Oooh, denormalized... feel the burn!"
|
|
106
|
-
puts
|
|
107
|
-
puts
|
|
108
|
-
puts
|
|
109
|
-
puts "Act II: Views"
|
|
110
|
-
puts
|
|
111
|
-
puts
|
|
112
|
-
sleep 2
|
|
113
|
-
|
|
114
|
-
puts "Let's find all the comments that go with our post."
|
|
115
|
-
puts "Our post has id #{post.id}, so lets find all the comments with that post_id."
|
|
116
|
-
puts
|
|
117
|
-
|
|
118
|
-
class Comment
|
|
119
|
-
view_by :post_id
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
comments = Comment.by_post_id :key => post.id
|
|
123
|
-
show comments
|
|
124
|
-
|
|
125
|
-
puts "That was too easy."
|
|
126
|
-
puts "We can even wrap it up in a finder on the Post class."
|
|
127
|
-
puts
|
|
128
|
-
|
|
129
|
-
class Post
|
|
130
|
-
def comments
|
|
131
|
-
Comment.by_post_id :key => id
|
|
132
|
-
end
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
show post.comments
|
|
136
|
-
puts "Gimme 5 minutes and I'll roll this into the framework. ;)"
|
|
137
|
-
puts
|
|
138
|
-
puts "There is a lot more that can be done with views, but a lot of the interesting stuff is joins, which of course range across types. We'll pick up where we left off, next time."
|
data/examples/word_count/markov
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
|
|
3
|
-
require File.expand_path(File.dirname(__FILE__)) + '/../../couchrest'
|
|
4
|
-
|
|
5
|
-
cr = CouchRest.new("http://localhost:5984")
|
|
6
|
-
@db = cr.database('word-count-example')
|
|
7
|
-
@word_memoizer = {}
|
|
8
|
-
|
|
9
|
-
def probable_follower_for(word)
|
|
10
|
-
@word_memoizer[word] ||= @db.view('markov/chain-reduce', :startkey => [word,nil], :endkey => [word,{}],:group_level => 2)
|
|
11
|
-
|
|
12
|
-
# puts
|
|
13
|
-
# puts "search #{word} #{wprobs[word]['rows'].length}"
|
|
14
|
-
# @word_memoizer[word]['rows'].sort_by{|r|r['value']}.each{|r|puts [r['value'],r['key']].inspect}
|
|
15
|
-
|
|
16
|
-
rows = @word_memoizer[word]['rows'].select{|r|(r['key'][1]!='')}.sort_by{|r|r['value']}
|
|
17
|
-
row = rows[(-1*[rows.length,5].min)..-1].sort_by{rand}[0]
|
|
18
|
-
row ? row['key'][1] : nil
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
word = ARGV[0]
|
|
23
|
-
words = [word]
|
|
24
|
-
|
|
25
|
-
while word
|
|
26
|
-
$stdout.print ' ' if words.length > 1
|
|
27
|
-
$stdout.print word
|
|
28
|
-
$stdout.flush
|
|
29
|
-
word = probable_follower_for(word)
|
|
30
|
-
words << word
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
$stdout.print '.'
|
|
34
|
-
$stdout.flush
|
|
35
|
-
puts
|
|
36
|
-
|
|
37
|
-
# `say #{words.join(' ')}`
|
|
38
|
-
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
function(doc){if(doc.text && doc.text.match(/united/)) emit([doc.title, doc.chunk],null)}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
require File.dirname(__FILE__) + '/../../couchrest'
|
|
2
|
-
|
|
3
|
-
couch = CouchRest.new("http://localhost:5984")
|
|
4
|
-
db = couch.database('word-count-example')
|
|
5
|
-
db.delete! rescue nil
|
|
6
|
-
db = couch.create_db('word-count-example')
|
|
7
|
-
|
|
8
|
-
books = {
|
|
9
|
-
'outline-of-science.txt' => 'http://www.gutenberg.org/files/20417/20417.txt',
|
|
10
|
-
'ulysses.txt' => 'http://www.gutenberg.org/dirs/etext03/ulyss12.txt',
|
|
11
|
-
'america.txt' => 'http://www.gutenberg.org/files/16960/16960.txt',
|
|
12
|
-
'da-vinci.txt' => 'http://www.gutenberg.org/dirs/etext04/7ldv110.txt'
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
books.each do |file, url|
|
|
16
|
-
pathfile = File.join(File.dirname(__FILE__),file)
|
|
17
|
-
`curl #{url} > #{pathfile}` unless File.exists?(pathfile)
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
books.keys.each do |book|
|
|
22
|
-
title = book.split('.')[0]
|
|
23
|
-
puts title
|
|
24
|
-
File.open(File.join(File.dirname(__FILE__),book),'r') do |file|
|
|
25
|
-
lines = []
|
|
26
|
-
chunk = 0
|
|
27
|
-
while line = file.gets
|
|
28
|
-
lines << line
|
|
29
|
-
if lines.length > 10
|
|
30
|
-
db.save({
|
|
31
|
-
:title => title,
|
|
32
|
-
:chunk => chunk,
|
|
33
|
-
:text => lines.join('')
|
|
34
|
-
})
|
|
35
|
-
chunk += 1
|
|
36
|
-
puts chunk
|
|
37
|
-
lines = []
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
# word_count = {
|
|
44
|
-
# :map => 'function(doc){
|
|
45
|
-
# var words = doc.text.split(/\W/);
|
|
46
|
-
# words.forEach(function(word){
|
|
47
|
-
# if (word.length > 0) emit([word,doc.title],1);
|
|
48
|
-
# });
|
|
49
|
-
# }',
|
|
50
|
-
# :reduce => 'function(key,combine){
|
|
51
|
-
# return sum(combine);
|
|
52
|
-
# }'
|
|
53
|
-
# }
|
|
54
|
-
#
|
|
55
|
-
# db.delete db.get("_design/word_count") rescue nil
|
|
56
|
-
#
|
|
57
|
-
# db.save({
|
|
58
|
-
# "_id" => "_design/word_count",
|
|
59
|
-
# :views => {
|
|
60
|
-
# :count => word_count,
|
|
61
|
-
# :words => {:map => word_count[:map]}
|
|
62
|
-
# }
|
|
63
|
-
# })
|
|
64
|
-
|
|
65
|
-
# puts "The books have been stored in your CouchDB. To initiate the MapReduce process, visit http://localhost:5984/_utils/ in your browser and click 'word-count-example', then select view 'words' or 'count'. The process could take about 15 minutes on an average MacBook."
|
|
66
|
-
#
|
|
67
|
-
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
require File.dirname(__FILE__) + '/../../couchrest'
|
|
2
|
-
|
|
3
|
-
couch = CouchRest.new("http://localhost:5984")
|
|
4
|
-
db = couch.database('word-count-example')
|
|
5
|
-
|
|
6
|
-
puts "Now that we've parsed all those books into CouchDB, the queries we can run are incredibly flexible."
|
|
7
|
-
puts "\nThe simplest query we can run is the total word count for all words in all documents:"
|
|
8
|
-
|
|
9
|
-
puts db.view('word_count/count').inspect
|
|
10
|
-
|
|
11
|
-
puts "\nWe can also narrow the query down to just one word, across all documents. Here is the count for 'flight' in all three books:"
|
|
12
|
-
|
|
13
|
-
word = 'flight'
|
|
14
|
-
params = {
|
|
15
|
-
:startkey => [word],
|
|
16
|
-
:endkey => [word,'Z']
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
puts db.view('word_count/count',params).inspect
|
|
20
|
-
|
|
21
|
-
puts "\nWe scope the query using startkey and endkey params to take advantage of CouchDB's collation ordering. Here are the params for the last query:"
|
|
22
|
-
puts params.inspect
|
|
23
|
-
|
|
24
|
-
puts "\nWe can also count words on a per-title basis."
|
|
25
|
-
|
|
26
|
-
title = 'da-vinci'
|
|
27
|
-
params = {
|
|
28
|
-
:key => [word, title]
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
puts db.view('word_count/count',params).inspect
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
puts "\nHere are the params for 'flight' in the da-vinci book:"
|
|
35
|
-
puts params.inspect
|
|
36
|
-
puts
|
|
37
|
-
puts 'The url looks like this:'
|
|
38
|
-
puts 'http://localhost:5984/word-count-example/_view/word_count/count?key=["flight","da-vinci"]'
|
|
39
|
-
puts "\nTry dropping that in your browser..."
|