Class: DbStager::HammerOfTheGods

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.exit_on_failure?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/db_stager/cli.rb', line 17

def self.exit_on_failure?
  true
end

.source_rootObject



13
14
15
# File 'lib/db_stager/cli.rb', line 13

def self.source_root
  File.join(File.dirname(__FILE__), '..', '..', 'templates')
end

Instance Method Details

#capture(dir = ".") ⇒ Object



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
48
49
50
# File 'lib/db_stager/cli.rb', line 23

def capture(dir=".")
  Dir.chdir(dir)

  run 'rake db:structure:dump'

  capture_file = File.join(Dir.pwd, "db", "structure.sql")
  File.open(capture_file, "a") do |file|
    db.tables.each do |table_name|
      next if excluded_tables.include?(table_name)
      items = db[table_name]
      items.each do |item|
        if fields[table_name]
          fields[table_name].each do |field_name, task|
            if task
              existing_value = item[field_name.to_sym]
              item[field_name.to_sym] = eval(task)
            else
              item[field_name.to_sym] = nil
            end
          end
          item
        end
        file.puts "#{items.insert_sql(item)};"
        file.puts
      end
    end
  end
end

#load(dir = ".") ⇒ Object



60
61
62
63
# File 'lib/db_stager/cli.rb', line 60

def load(dir=".")
  Dir.chdir(dir)
  run 'rake db:structure:load'
end