Created
May 26, 2016 08:31
-
-
Save mikeymckay/5b4278e4e175d19d13e13b8bb53487a9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env ruby | |
require 'rubygems' | |
require 'couchrest' | |
require 'json' | |
@db = CouchRest.new(ARGV[0]).database!(ARGV[1]) | |
#Get all .coffee files | |
Dir.glob("*.coffee").each do |view| | |
next unless view.match(/__reduce/).nil? | |
next if view == "executeViews.coffee" | |
view_name = view.sub(/\.coffee/,"") | |
document_id = "_design/#{view_name}" | |
map = File.read(view) | |
local_view_doc = { | |
"_id" => document_id, | |
"language" => "coffeescript", | |
:views => { | |
"#{view_name}" => { | |
:map => map | |
} | |
} | |
} | |
reduce_file = view.sub(/\.coffee/,"__reduce.coffee") | |
if File.exist? reduce_file | |
reduce = File.read(view.sub(/\.coffee/,"__reduce.coffee")) | |
local_view_doc[:views][view_name][:reduce] = reduce | |
end | |
begin | |
db_view_doc = @db.get(document_id) | |
local_view_doc["_rev"] = db_view_doc["_rev"] if db_view_doc | |
rescue | |
end | |
puts "Saving view #{view}" | |
@db.save_doc(local_view_doc) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment