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
# 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
    {'database' => {
       'url' => "http://localhost:5984/#{name}"
    }}.to_yaml.split("\n")[1..-1].join("\n") + "\n"
  end

  copy_file 'validation.coffee.erb', 'config/validation.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



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

def push
  Dayvan.project.create_database!
  Dayvan.project.push!
rescue SocketError, Errno::ECONNREFUSED, RestClient::Unauthorized
  abort "fatal: Couldn't connect to CouchDB at #{Dayvan.project.db.url}"
rescue Dayvan::ConfigError
  abort "fatal: No Dayvan config found, searched for \n" +
    Dayvan.project.config_search_paths.
      map {|p| ' - ' + p.relative_path_from(Dayvan.project.dir).to_s}.
      join("\n") +
      "\n"
end