Class: Ridgepole::Delta

Inherits:
Object
  • Object
show all
Defined in:
lib/ridgepole/delta.rb

Instance Method Summary collapse

Constructor Details

#initialize(delta, options = {}) ⇒ Delta

Returns a new instance of Delta.



2
3
4
5
# File 'lib/ridgepole/delta.rb', line 2

def initialize(delta, options = {})
  @delta = delta
  @options = options
end

Instance Method Details

#differ?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/ridgepole/delta.rb', line 41

def differ?
  not script.empty?
end

#migrateObject



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/ridgepole/delta.rb', line 7

def migrate
  if log_file = @options[:log_file]
    result = ActiveRecord::Migration.record_time do
      migrate0
    end

    open(log_file, 'wb') {|f| f.puts JSON.pretty_generate(result) }
  else
    migrate0
  end
end

#scriptObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ridgepole/delta.rb', line 19

def script
  buf = StringIO.new

  (@delta[:add] || {}).each do |table_name, attrs|
    append_create_table(table_name, attrs, buf)
  end

  (@delta[:rename] || {}).each do |table_name, attrs|
    append_rename_table(table_name, attrs, buf)
  end

  (@delta[:change] || {}).each do |table_name, attrs|
    append_change(table_name, attrs, buf)
  end

  (@delta[:delete] || {}).each do |table_name, attrs|
    append_drop_table(table_name, attrs, buf)
  end

  buf.string.strip
end