lib/synchronised_migration/result.rb in synchronised_migration-2.2.0 vs lib/synchronised_migration/result.rb in synchronised_migration-3.0.0
- old
+ new
@@ -1,21 +1,52 @@
-require 'synchronised_migration'
+require "synchronised_migration"
-class SynchronisedMigration::Result
- attr_accessor :error
+module SynchronisedMigration
+ MIGRATION_SUCCESS = 0
+ PREVIOUS_SUCCESS = 1
+ PREVIOUS_FAILED = 2
+ MIGRATION_FAILED = 3
- def initialize(error = nil)
- @error = error
- end
+ PREVIOUS_FAILED_MSG = "Halting the script because the previous migration failed."
+ MIGRATION_FAILED_MSG = "Migration command failed."
- def success?
- error.nil?
- end
+ class Result
+ attr_reader :code
- def self.ok
- self.new
- end
+ def initialize(code)
+ @code = code
+ end
- def self.fail(error)
- self.new error
+ def successful?
+ [MIGRATION_SUCCESS, PREVIOUS_SUCCESS].include?(code)
+ end
+
+ def failure?
+ !successful?
+ end
+
+ def error_msg
+ case code
+ when MIGRATION_FAILED
+ MIGRATION_FAILED_MSG
+ when PREVIOUS_FAILED
+ PREVIOUS_FAILED_MSG
+ end
+ end
+
+ def self.ok
+ new(MIGRATION_SUCCESS)
+ end
+
+ def self.migration_already_completed
+ new(PREVIOUS_SUCCESS)
+ end
+
+ def self.previous_migration_failed
+ new(PREVIOUS_FAILED)
+ end
+
+ def self.migration_failed
+ new(MIGRATION_FAILED)
+ end
end
end