Class: Databasion::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/databasion/application.rb

Class Method Summary collapse

Class Method Details

.copy_config(dir, name) ⇒ Object



90
91
92
93
94
95
# File 'lib/databasion/application.rb', line 90

def self.copy_config(dir, name)
  base = File.dirname(File.expand_path(__FILE__)) + "/../../" + "config/example.google.yml"
  path = dir + "/" + "%s/config/google.yml" % name
  FileUtils.cp base, path
  Databasion::LOGGER.info "copied: %s" % path
end

.create_base(dir, name) ⇒ Object



78
79
80
81
82
# File 'lib/databasion/application.rb', line 78

def self.create_base(dir, name)
  path = dir + "/" + name
  FileUtils.mkdir path
  Databasion::LOGGER.info "created: %s" % path
end

.create_config(dir, name) ⇒ Object



84
85
86
87
88
# File 'lib/databasion/application.rb', line 84

def self.create_config(dir, name)
  path = dir + "/" + "%s/config" % name
  FileUtils.mkdir path
  Databasion::LOGGER.info "created: %s" % path
end

.create_project(opts) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/databasion/application.rb', line 65

def self.create_project(opts)
  dir = Dir.pwd
  if File.exist?(dir + "/" + opts[:create])
    Databasion::LOGGER.info "A directory with the name %s already exists" % opts[:create]
  else
    Databasion::LOGGER.info "Creating new project directory..."
    create_base(dir, opts[:create])
    create_config(dir, opts[:create])
    copy_config(dir, opts[:create])
    Databasion::LOGGER.info "Done."
  end
end

.execute_databasion(opts) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/databasion/application.rb', line 44

def self.execute_databasion(opts)
  if opts[:cron]
    Databasion.run('cron', opts[:config], opts)
  end
  if opts[:google]
    Databasion.run('google', opts[:config], opts)
  end
  if opts[:migrate]
    Databasion.run('migrate', opts[:config], opts)
  end
  if opts[:load]
    Databasion.run('load', opts[:config], opts)
  end
  if opts[:svn]
    Databasion.run('svn', opts[:config], opts)
  end
  if opts[:git]
    Databasion.run('git', opts[:config], opts)
  end
end

.runObject



8
9
10
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
40
41
42
# File 'lib/databasion/application.rb', line 8

def self.run
  opts = Trollop::options do
    banner <<-EOS
  Databasion - A Google Spreadsheet/Excel -> YAML -> Ruby Migration Database Tool

  Usage:
      databasion [options]
  where [options] are:
    EOS
    opt :create, "Create a base deploy directory", :type => String
    opt :config, "Path to YAML config.  Looks for config/google.yml by default", :type => String
    opt :google, "Load data from Google Spreadsheets"
    opt :migrate, "Migrate after GoogleLoading"
    opt :load, "Load parsed YAML data into migrated database"
    opt :diff, "Manually check the diff of each database update from the load command"
    opt :svn, "Auto commit the project files (assuming it has been committed to SVN)"
    opt :git, "Auto commit the project files (assuming a working git repo)"
    opt :cron, "Run the version control system via crontab and update on version changes"
  end
  if opts[:config].nil? and opts[:create].nil?
    config = "config/google.yml"
    puts Dir.pwd
    if File.exist?(Dir.pwd + "/" + config)
      opts[:config] = config
    else  
      Trollop::die :config, "A YAML config must be specified"
    end
  end

  if opts[:create]
    create_project(opts)
  else
    execute_databasion(opts)
  end
end