Class: ActiveMigration::Base
- Inherits:
-
Object
- Object
- ActiveMigration::Base
- Defined in:
- lib/godwit/active_migration.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#debugger ⇒ Object
:nodoc:.
-
#handle_error ⇒ Object
:nodoc:.
-
#handle_success ⇒ Object
:nodoc:.
-
#initialize ⇒ Base
constructor
:nodoc:.
-
#no_resolve ⇒ Object
:nodoc:.
-
#resolve ⇒ Object
:nodoc:.
-
#success ⇒ Object
:nodoc:.
Constructor Details
#initialize ⇒ Base
:nodoc:
4 5 6 7 8 9 10 |
# File 'lib/godwit/active_migration.rb', line 4 def initialize #:nodoc: @error = false @count = 0 @backspaces = -1 @percentage = 0 @printed_class = false end |
Instance Method Details
#debugger ⇒ Object
:nodoc:
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/godwit/active_migration.rb', line 55 def debugger #:nodoc: system('clear') puts "Godwit " + Godwit::VERSION::STRING puts "\nCurrent Migration: " + self.class.to_s puts "\nYou encountered an invalid record while trying to save. You can attempt to reconcile this in the debug console." puts "When you are done type 'exit' and godwit will try to save the record again. Do not try to save the record with #save yourself!" puts "Use methods like #valid? and #errors to determine the problem." puts "\nYou have the following instance variables available to manipulate:" puts "\n@active_record\t\tThis is the record that failed to save. You should fix this record." puts "@legacy_record\t\tThis should only be used for information. It is unwise to manipulate this object." puts "@mapping\t\tThis should only be used for information. It is unwise to manipulate this object." puts "\nLoading Debug Console..." puts "\n" IRB.start_session(binding) end |
#handle_error ⇒ Object
:nodoc:
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/godwit/active_migration.rb', line 12 def handle_error #:nodoc: if Godwit::Config[:silence] || !Godwit::Config[:debug] puts "\n\n\n" raise ActiveMigrationError, 'Failed to save the active record. You should check the logs or run migrate with the -D option to debug.' end unless @error || @skip debugger @error = true else no_resolve @error = false handle_error end end |
#handle_success ⇒ Object
:nodoc:
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/godwit/active_migration.rb', line 27 def handle_success() #:nodoc: return if Godwit::Config[:silence] unless @error success else resolve success @error = false end end |
#no_resolve ⇒ Object
:nodoc:
47 48 49 50 51 52 53 |
# File 'lib/godwit/active_migration.rb', line 47 def no_resolve #:nodoc: system('clear') puts "You have not resolved the error!" puts "Please make sure you check that @active_record.valid? is true before you type 'exit'." puts "\nYou will return to the debug console in 5 seconds..." sleep(5) end |
#resolve ⇒ Object
:nodoc:
38 39 40 41 42 43 44 45 |
# File 'lib/godwit/active_migration.rb', line 38 def resolve #:nodoc: system('clear') puts "The error has been resolved." puts "\nGodwit will continue the migration in 5 seconds..." sleep(5) system('clear') print Godwit::Buffer.buffer end |
#success ⇒ Object
:nodoc:
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/godwit/active_migration.rb', line 71 def success #:nodoc: if @active_record.is_a?(Array) if @active_array if @active_array != @active_record.object_id @count += 1 @active_array = @active_record.object_id end else @count += 1 @active_array = @active_record.object_id end else @count += 1 end percent = ((@count.to_f / @num_of_records.to_f) * 100).to_i.to_s return if (@percentage == percent) && @count > 1 @percentage = percent if @count == 1 && !@printed_class Godwit::Buffer.print("\n" + self.class.to_s + "\t\t\t") @printed_class = true end Godwit::Buffer.print(("\b" * (@backspaces + 1)) + @percentage + '%') @backspaces = @percentage.length end |