Skip to content

Commit

Permalink
Minor changes to support create views on No Editor console.
Browse files Browse the repository at this point in the history
  • Loading branch information
sreeix committed Mar 11, 2011
1 parent 64e1fca commit 3d424df
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 22 deletions.
2 changes: 2 additions & 0 deletions TODO
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Attachments
Try and save views. Save to temp view, show results to the users and then save to real Try and save views. Save to temp view, show results to the users and then save to real
Username password based access Username password based access


Debugging information on debug

Bigcouch Bigcouch
Nodes Management. Nodes Management.


Expand Down
43 changes: 24 additions & 19 deletions lib/couchup/commands/create.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4,35 +4,40 @@ class Create
def run(*params) def run(*params)
what = params.shift.to_s what = params.shift.to_s
if(what == 'view') if(what == 'view')
create_view(params.first) create_view(params.shift, *params)
else else
Couchup.server.database!(params.first) Couchup.server.database!(params.first)
Use.new.run(params.first) Use.new.run(params.first)
end end
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? raise "Please set your EDITOR env variable before using view" if ENV['EDITOR'].nil?
view = ::Couchup::View.new(name) view = ::Couchup::View.new(name)
file = Tempfile.new(name.gsub("/", "_")) if(params.size == 0)
tmp_file_path = file.path file = Tempfile.new(name.gsub("/", "_"))
file.write("------BEGIN Map-------\n") tmp_file_path = file.path
file.write( view.map? ? view.map : ::Couchup::View::MAP_TEMPLATE) file.write("------BEGIN Map-------\n")
file.write("\n------END------\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("\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(view.reduce? ? view.reduce: ::Couchup::View::REDUCE_TEMPLATE )
file.write("\n------END------\n") file.write("\n------END------\n")
file.write("\nDelete Everything to do nothing.\n") file.write("\nDelete Everything to do nothing.\n")
file.close file.close


`#{ENV['EDITOR']} #{tmp_file_path}` `#{ENV['EDITOR']} #{tmp_file_path}`
contents = File.open(tmp_file_path).read contents = File.open(tmp_file_path).read
unless contents.blank? unless contents.blank?
::Couchup::View.create(name, contents) ::Couchup::View.create_from_file(name, contents)
end
file.close
file.unlink
else
map = params.shift
::Couchup::View.create(name, map, params.shift)
end end
file.close
file.unlink
end end


def self.describe def self.describe
Expand Down
9 changes: 6 additions & 3 deletions lib/couchup/view.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -57,10 +57,13 @@ def delete!
end end




def self.create(name, file_contents) def self.create_from_file(name, file_contents)
v = new(name)

map, reduce = parse(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.map = map
v.reduce = reduce unless reduce.blank? v.reduce = reduce unless reduce.blank?
ap v ap v
Expand Down

0 comments on commit 3d424df

Please sign in to comment.