Class: Ridgepole::Delta
- Inherits:
-
Object
- Object
- Ridgepole::Delta
- Defined in:
- lib/ridgepole/delta.rb
Constant Summary collapse
- SCRIPT_NAME =
'<Schema>'
Instance Method Summary collapse
- #differ? ⇒ Boolean
-
#initialize(delta, options = {}) ⇒ Delta
constructor
A new instance of Delta.
- #migrate(options = {}) ⇒ Object
- #script ⇒ Object
Constructor Details
#initialize(delta, options = {}) ⇒ Delta
Returns a new instance of Delta.
4 5 6 7 |
# File 'lib/ridgepole/delta.rb', line 4 def initialize(delta, = {}) @delta = delta @options = end |
Instance Method Details
#differ? ⇒ Boolean
43 44 45 |
# File 'lib/ridgepole/delta.rb', line 43 def differ? not script.empty? end |
#migrate(options = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/ridgepole/delta.rb', line 9 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 |
#script ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ridgepole/delta.rb', line 21 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 |