Class: Dayvan::Cli

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/dayvan/cli.rb

Instance Method Summary collapse

Instance Method Details

#initObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/dayvan/cli.rb', line 11

def init
  destination_root = Pathname.pwd
  source_path = Pathname(__FILE__).dirname.expand_path
  name = destination_root.basename.to_s


  empty_directory 'config'

  create_file "config/#{name}.yaml" do
    {'designs' => [name.to_s],
     'database' => {
       'url' => "http://localhost:5984/#{name}"
     }
    }.to_yaml.split("\n")[1..-1].join("\n") + "\n"
  end

  copy_file 'security.coffee.erb', 'config/security.coffee'

  empty_directory 'views'
  copy_file 'all.coffee.erb', 'views/all.coffee'
  copy_file 'size.coffee.erb', 'views/size.coffee'

  empty_directory 'public'
  @name = name
  @version = Dayvan.version
  template 'welcome.html.erb', 'public/index.html'

  puts "Initialized CouchApp in #{destination_root}"
end

#pushObject



42
43
44
45
46
47
48
49
# File 'lib/dayvan/cli.rb', line 42

def push
  Dayvan.project.create_database!
  Dayvan.project.push!
rescue Errno::ECONNREFUSED, RestClient::Unauthorized
  abort "fatal: Couldn't connect to CouchDB at #{Dayvan.project.db.url}"
rescue Dayvan::ConfigError
  abort "fatal: Not a Dayvan app"
end