remove couchview
This commit is contained in:
parent
cc6039cbd4
commit
c435aa0932
3
Rakefile
3
Rakefile
|
@ -5,7 +5,7 @@ require 'rake/gempackagetask'
|
||||||
|
|
||||||
spec = Gem::Specification.new do |s|
|
spec = Gem::Specification.new do |s|
|
||||||
s.name = "couchrest"
|
s.name = "couchrest"
|
||||||
s.version = "0.10.1"
|
s.version = "0.11.1"
|
||||||
s.date = "2008-11-22"
|
s.date = "2008-11-22"
|
||||||
s.summary = "Lean and RESTful interface to CouchDB."
|
s.summary = "Lean and RESTful interface to CouchDB."
|
||||||
s.email = "jchris@grabb.it"
|
s.email = "jchris@grabb.it"
|
||||||
|
@ -19,7 +19,6 @@ spec = Gem::Specification.new do |s|
|
||||||
s.extra_rdoc_files = %w( README.rdoc LICENSE THANKS )
|
s.extra_rdoc_files = %w( README.rdoc LICENSE THANKS )
|
||||||
s.require_path = "lib"
|
s.require_path = "lib"
|
||||||
s.bindir = 'bin'
|
s.bindir = 'bin'
|
||||||
s.executables << 'couchview'
|
|
||||||
s.executables << 'couchdir'
|
s.executables << 'couchdir'
|
||||||
s.executables << 'couchapp'
|
s.executables << 'couchapp'
|
||||||
s.add_dependency("json", ">= 1.1.2")
|
s.add_dependency("json", ">= 1.1.2")
|
||||||
|
|
|
@ -1,48 +0,0 @@
|
||||||
#!/usr/bin/env ruby
|
|
||||||
|
|
||||||
require 'optparse'
|
|
||||||
require 'couchrest'
|
|
||||||
|
|
||||||
%w(generate push).each do |file|
|
|
||||||
require File.dirname(__FILE__) + "/../lib/couchrest/commands/#{file}"
|
|
||||||
end
|
|
||||||
|
|
||||||
# Set defaults
|
|
||||||
options = {
|
|
||||||
:loud => true,
|
|
||||||
}
|
|
||||||
|
|
||||||
opts = OptionParser.new do |opts|
|
|
||||||
opts.banner = "Usage: #$0 [options] (push|generate) directory database"
|
|
||||||
opts.on('-q', '--quiet', "Omit extra debug info") do
|
|
||||||
options[:loud] = false
|
|
||||||
end
|
|
||||||
opts.on_tail('-h', '--help [push|generate]', "Display detailed help and exit") do |help_command|
|
|
||||||
puts opts
|
|
||||||
case help_command
|
|
||||||
when "push"
|
|
||||||
puts CouchRest::Commands::Push.help
|
|
||||||
when "generate"
|
|
||||||
puts CouchRest::Commands::Generate.help
|
|
||||||
end
|
|
||||||
exit
|
|
||||||
end
|
|
||||||
end
|
|
||||||
opts.parse!(ARGV)
|
|
||||||
|
|
||||||
options[:command] = ARGV.shift
|
|
||||||
options[:directory] = ARGV.shift
|
|
||||||
options[:trailing_args] = ARGV
|
|
||||||
|
|
||||||
# There must be a better way to check for extra required args
|
|
||||||
unless (["push", "generate"].include?(options[:command]) && options[:directory] && options[:trailing_args])
|
|
||||||
puts(opts)
|
|
||||||
exit
|
|
||||||
end
|
|
||||||
|
|
||||||
case options[:command]
|
|
||||||
when "push"
|
|
||||||
CouchRest::Commands::Push.run(options)
|
|
||||||
when "generate"
|
|
||||||
CouchRest::Commands::Generate.run(options)
|
|
||||||
end
|
|
|
@ -1,17 +1,16 @@
|
||||||
Gem::Specification.new do |s|
|
Gem::Specification.new do |s|
|
||||||
s.extra_rdoc_files = ["README.rdoc", "LICENSE", "THANKS"]
|
s.extra_rdoc_files = ["README.rdoc", "LICENSE", "THANKS"]
|
||||||
s.date = "Sat Nov 22 00:00:00 -0800 2008"
|
s.date = "Sat Nov 22 00:00:00 -0800 2008"
|
||||||
s.executables = ["couchview", "couchdir", "couchapp"]
|
s.executables = ["couchdir", "couchapp"]
|
||||||
s.authors = ["J. Chris Anderson"]
|
s.authors = ["J. Chris Anderson"]
|
||||||
s.required_rubygems_version = ">= 0"
|
s.required_rubygems_version = ">= 0"
|
||||||
s.version = "0.10.1"
|
s.version = "0.11.1"
|
||||||
s.files = ["LICENSE",
|
s.files = ["LICENSE",
|
||||||
"README.rdoc",
|
"README.rdoc",
|
||||||
"Rakefile",
|
"Rakefile",
|
||||||
"THANKS",
|
"THANKS",
|
||||||
"bin/couchapp",
|
"bin/couchapp",
|
||||||
"bin/couchdir",
|
"bin/couchdir",
|
||||||
"bin/couchview",
|
|
||||||
"examples/model",
|
"examples/model",
|
||||||
"examples/model/example.rb",
|
"examples/model/example.rb",
|
||||||
"examples/word_count",
|
"examples/word_count",
|
||||||
|
@ -43,11 +42,21 @@ Gem::Specification.new do |s|
|
||||||
"lib/couchrest/helper/file_manager.rb",
|
"lib/couchrest/helper/file_manager.rb",
|
||||||
"lib/couchrest/helper/pager.rb",
|
"lib/couchrest/helper/pager.rb",
|
||||||
"lib/couchrest/helper/streamer.rb",
|
"lib/couchrest/helper/streamer.rb",
|
||||||
"lib/couchrest/helper/templates",
|
"lib/couchrest/helper/template-app",
|
||||||
"lib/couchrest/helper/templates/bar.txt",
|
"lib/couchrest/helper/template-app/_attachments",
|
||||||
"lib/couchrest/helper/templates/example-map.js",
|
"lib/couchrest/helper/template-app/_attachments/index.html",
|
||||||
"lib/couchrest/helper/templates/example-reduce.js",
|
"lib/couchrest/helper/template-app/foo",
|
||||||
"lib/couchrest/helper/templates/index.html",
|
"lib/couchrest/helper/template-app/foo/bar.txt",
|
||||||
|
"lib/couchrest/helper/template-app/forms",
|
||||||
|
"lib/couchrest/helper/template-app/forms/example-form.js",
|
||||||
|
"lib/couchrest/helper/template-app/forms/lib",
|
||||||
|
"lib/couchrest/helper/template-app/forms/lib/example-template.html",
|
||||||
|
"lib/couchrest/helper/template-app/views",
|
||||||
|
"lib/couchrest/helper/template-app/views/_lib",
|
||||||
|
"lib/couchrest/helper/template-app/views/_lib/helper.js",
|
||||||
|
"lib/couchrest/helper/template-app/views/example",
|
||||||
|
"lib/couchrest/helper/template-app/views/example/map.js",
|
||||||
|
"lib/couchrest/helper/template-app/views/example/reduce.js",
|
||||||
"lib/couchrest/monkeypatches.rb",
|
"lib/couchrest/monkeypatches.rb",
|
||||||
"lib/couchrest.rb",
|
"lib/couchrest.rb",
|
||||||
"spec/couchapp_spec.rb",
|
"spec/couchapp_spec.rb",
|
||||||
|
|
|
@ -116,91 +116,6 @@ module CouchRest
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# deprecated
|
|
||||||
def push_views(view_dir)
|
|
||||||
puts "WARNING this is deprecated, use `couchapp` script"
|
|
||||||
designs = {}
|
|
||||||
|
|
||||||
Dir["#{view_dir}/**/*.*"].each do |design_doc|
|
|
||||||
design_doc_parts = design_doc.split('/')
|
|
||||||
next if /^lib\..*$/.match design_doc_parts.last
|
|
||||||
pre_normalized_view_name = design_doc_parts.last.split("-")
|
|
||||||
view_name = pre_normalized_view_name[0..pre_normalized_view_name.length-2].join("-")
|
|
||||||
|
|
||||||
folder = design_doc_parts[-2]
|
|
||||||
|
|
||||||
designs[folder] ||= {}
|
|
||||||
designs[folder]["views"] ||= {}
|
|
||||||
design_lang = design_doc_parts.last.split(".").last
|
|
||||||
designs[folder]["language"] ||= LANGS[design_lang]
|
|
||||||
|
|
||||||
libs = ""
|
|
||||||
Dir["#{view_dir}/lib.#{design_lang}"].collect do |global_lib|
|
|
||||||
libs << open(global_lib).read
|
|
||||||
libs << "\n"
|
|
||||||
end
|
|
||||||
Dir["#{view_dir}/#{folder}/lib.#{design_lang}"].collect do |global_lib|
|
|
||||||
libs << open(global_lib).read
|
|
||||||
libs << "\n"
|
|
||||||
end
|
|
||||||
if design_doc_parts.last =~ /-map/
|
|
||||||
designs[folder]["views"][view_name] ||= {}
|
|
||||||
designs[folder]["views"][view_name]["map"] = read(design_doc, libs)
|
|
||||||
end
|
|
||||||
|
|
||||||
if design_doc_parts.last =~ /-reduce/
|
|
||||||
designs[folder]["views"][view_name] ||= {}
|
|
||||||
designs[folder]["views"][view_name]["reduce"] = read(design_doc, libs)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# cleanup empty maps and reduces
|
|
||||||
designs.each do |name, props|
|
|
||||||
props["views"].each do |view, funcs|
|
|
||||||
next unless view.include?("reduce")
|
|
||||||
props["views"].delete(view) unless funcs.keys.include?("reduce")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
designs.each do |k,v|
|
|
||||||
create_or_update("_design/#{k}", v)
|
|
||||||
end
|
|
||||||
|
|
||||||
designs
|
|
||||||
end
|
|
||||||
|
|
||||||
def pull_views(view_dir)
|
|
||||||
prefix = "_design"
|
|
||||||
ds = db.documents(:startkey => '#{prefix}/', :endkey => '#{prefix}/ZZZZZZZZZ')
|
|
||||||
ds['rows'].collect{|r|r['id']}.each do |id|
|
|
||||||
puts directory = id.split('/').last
|
|
||||||
FileUtils.mkdir_p(File.join(view_dir,directory))
|
|
||||||
views = db.get(id)['views']
|
|
||||||
|
|
||||||
vgroups = views.keys.group_by{|k|k.sub(/\-(map|reduce)$/,'')}
|
|
||||||
vgroups.each do|g,vs|
|
|
||||||
mapname = vs.find {|v|views[v]["map"]}
|
|
||||||
if mapname
|
|
||||||
# save map
|
|
||||||
mapfunc = views[mapname]["map"]
|
|
||||||
mapfile = File.join(view_dir, directory, "#{g}-map.js") # todo support non-js views
|
|
||||||
File.open(mapfile,'w') do |f|
|
|
||||||
f.write mapfunc
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
reducename = vs.find {|v|views[v]["reduce"]}
|
|
||||||
if reducename
|
|
||||||
# save reduce
|
|
||||||
reducefunc = views[reducename]["reduce"]
|
|
||||||
reducefile = File.join(view_dir, directory, "#{g}-reduce.js") # todo support non-js views
|
|
||||||
File.open(reducefile,'w') do |f|
|
|
||||||
f.write reducefunc
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def dir_to_fields(dir)
|
def dir_to_fields(dir)
|
||||||
fields = {}
|
fields = {}
|
||||||
|
@ -266,30 +181,5 @@ module CouchRest
|
||||||
def md5 string
|
def md5 string
|
||||||
Digest::MD5.hexdigest(string)
|
Digest::MD5.hexdigest(string)
|
||||||
end
|
end
|
||||||
|
|
||||||
# deprecated
|
|
||||||
def read(file, libs=nil)
|
|
||||||
st = open(file).read
|
|
||||||
st.sub!(/(\/\/|#)include-lib/,libs) if libs
|
|
||||||
st
|
|
||||||
end
|
|
||||||
|
|
||||||
def create_or_update(id, fields)
|
|
||||||
existing = @db.get(id) rescue nil
|
|
||||||
|
|
||||||
if existing
|
|
||||||
updated = existing.merge(fields)
|
|
||||||
if existing != updated
|
|
||||||
say "replacing #{id}"
|
|
||||||
db.save(updated)
|
|
||||||
else
|
|
||||||
say "skipping #{id}"
|
|
||||||
end
|
|
||||||
else
|
|
||||||
say "creating #{id}"
|
|
||||||
db.save(fields.merge({"_id" => id}))
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue