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



95
96
97
98
99
100
# File 'lib/databasion/application.rb', line 95

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



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

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

.create_config(dir, name) ⇒ Object



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

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



70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/databasion/application.rb', line 70

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



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/databasion/application.rb', line 49

def self.execute_databasion(opts)
  if opts[:cron]
    Databasion.run('cron', opts)
  end
  if opts[:google]
    Databasion.run('google', opts)
  end
  if opts[:migrate]
    Databasion.run('migrate', opts)
  end
  if opts[:load]
    Databasion.run('load', opts)
  end
  if opts[:svn]
    Databasion.run('svn', opts)
  end
  if opts[:git]
    Databasion.run('git', 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
43
44
45
46
47
# 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"
    opt :env, "Define the environment with which to run.  Default: development", :type => String
  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[:env]
    opts[:env] = 'development'
  end

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