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 "  Databasion - A Google Spreadsheet/Excel -> YAML -> Ruby Migration Database Tool\n\n  Usage:\n      databasion [options]\n  where [options] are:\n    EOS\n    opt :create, \"Create a base deploy directory\", :type => String\n    opt :config, \"Path to YAML config.  Looks for config/google.yml by default\", :type => String\n    opt :google, \"Load data from Google Spreadsheets\"\n    opt :migrate, \"Migrate after GoogleLoading\"\n    opt :load, \"Load parsed YAML data into migrated database\"\n    opt :diff, \"Manually check the diff of each database update from the load command\"\n    opt :svn, \"Auto commit the project files (assuming it has been committed to SVN)\"\n    opt :git, \"Auto commit the project files (assuming a working git repo)\"\n    opt :cron, \"Run the version control system via crontab and update on version changes\"\n    opt :env, \"Define the environment with which to run.  Default: development\", :type => String\n  end\n  if opts[:config].nil? and opts[:create].nil?\n    config = \"config/google.yml\"\n    puts Dir.pwd\n    if File.exist?(Dir.pwd + \"/\" + config)\n      opts[:config] = config\n    else  \n      Trollop::die :config, \"A YAML config must be specified\"\n    end\n  end\n  \n  if !opts[:env]\n    opts[:env] = 'development'\n  end\n\n  if opts[:create]\n    create_project(opts)\n  else\n    execute_databasion(opts)\n  end\nend\n"