Skip to content
Browse files

Minor changes to support create views on No Editor console.

  • Loading branch information...
1 parent 64e1fca commit 3d424df5342ca8d15ab9d9b09cd8c9ad33d1e9fc @sreeix committed Mar 12, 2011
Showing with 32 additions and 22 deletions.
  1. +2 −0 TODO
  2. +24 −19 lib/couchup/commands/create.rb
  3. +6 −3 lib/couchup/view.rb
View
2 TODO
@@ -8,6 +8,8 @@ Attachments
Try and save views. Save to temp view, show results to the users and then save to real
Username password based access
+Debugging information on debug
+
Bigcouch
Nodes Management.
View
43 lib/couchup/commands/create.rb
@@ -4,35 +4,40 @@ class Create
def run(*params)
what = params.shift.to_s
if(what == 'view')
- create_view(params.first)
+ create_view(params.shift, *params)
else
Couchup.server.database!(params.first)
Use.new.run(params.first)
end
end
- def create_view(name)
+ def create_view(name, *params)
raise "Please set your EDITOR env variable before using view" if ENV['EDITOR'].nil?
- view = ::Couchup::View.new(name)
- file = Tempfile.new(name.gsub("/", "_"))
- tmp_file_path = file.path
- file.write("------BEGIN Map-------\n")
- file.write( view.map? ? view.map : ::Couchup::View::MAP_TEMPLATE)
- file.write("\n------END------\n")
+ view = ::Couchup::View.new(name)
+ if(params.size == 0)
+ file = Tempfile.new(name.gsub("/", "_"))
+ tmp_file_path = file.path
+ file.write("------BEGIN Map-------\n")
+ file.write( view.map? ? view.map : ::Couchup::View::MAP_TEMPLATE)
+ file.write("\n------END------\n")
- file.write("\n------BEGIN Reduce(Remove the function if you don't want a reduce)-------\n")
- file.write(view.reduce? ? view.reduce: ::Couchup::View::REDUCE_TEMPLATE )
- file.write("\n------END------\n")
- file.write("\nDelete Everything to do nothing.\n")
- file.close
+ file.write("\n------BEGIN Reduce(Remove the function if you don't want a reduce)-------\n")
+ file.write(view.reduce? ? view.reduce: ::Couchup::View::REDUCE_TEMPLATE )
+ file.write("\n------END------\n")
+ file.write("\nDelete Everything to do nothing.\n")
+ file.close
- `#{ENV['EDITOR']} #{tmp_file_path}`
- contents = File.open(tmp_file_path).read
- unless contents.blank?
- ::Couchup::View.create(name, contents)
+ `#{ENV['EDITOR']} #{tmp_file_path}`
+ contents = File.open(tmp_file_path).read
+ unless contents.blank?
+ ::Couchup::View.create_from_file(name, contents)
+ end
+ file.close
+ file.unlink
+ else
+ map = params.shift
+ ::Couchup::View.create(name, map, params.shift)
end
- file.close
- file.unlink
end
def self.describe
View
9 lib/couchup/view.rb
@@ -57,10 +57,13 @@ def delete!
end
- def self.create(name, file_contents)
- v = new(name)
-
+ def self.create_from_file(name, file_contents)
map, reduce = parse(file_contents)
+ create(name, map, reduce)
+ end
+
+ def self.create(name, map, reduce)
+ v = new(name)
v.map = map
v.reduce = reduce unless reduce.blank?
ap v

0 comments on commit 3d424df

Please sign in to comment.
Something went wrong with that request. Please try again.