Class: Couchup::Commands::Create
- Inherits:
-
Object
- Object
- Couchup::Commands::Create
- Includes:
- Couchup::CommandExtensions
- Defined in:
- lib/couchup/commands/create.rb
Class Method Summary collapse
Instance Method Summary collapse
Methods included from Couchup::CommandExtensions
Class Method Details
.describe ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/couchup/commands/create.rb', line 47 def self.describe { :description => "Creates a new database and switches to the database", :usage => " create :database | :view , name", :examples => ["create :database, riders", "create :view, 'Riders/test'"] } end |
Instance Method Details
#create_view(name, *params) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/couchup/commands/create.rb', line 17 def create_view(name, *params) raise "Please set your EDITOR env variable before using view" if ENV['EDITOR'].nil? 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 `#{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 reduce = params.shift ::Couchup::View.create(name, map, reduce) end end |
#run(*params) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/couchup/commands/create.rb', line 5 def run(*params) what = params.shift.to_s if(what == 'view') needs_db! create_view(params.shift, *params) else new_db = params.shift.to_s Couchup.server.database!(new_db) Use.new.run(new_db) end end |