Created
December 3, 2016 20:02
-
-
Save amancevice/fd10dc533d80ceab255213dd8f7f366a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def block_helper begin_msg, ensure_msg | |
start = Time.now | |
puts begin_msg.call(start) | |
begin | |
yield | |
rescue Exception => err | |
abort err.to_s | |
ensure | |
puts ensure_msg.call(start) | |
end | |
end | |
def migration name | |
begin_msg = -> start {"== #{start.strftime "%Y%m%d%H%M%S"} #{name} ".ljust(79, "=")} | |
ensure_msg = -> start {"== #{start.strftime "%Y%m%d%H%M%S"} #{name} (#{Time.now.minus_with_coercion(start).round(4)}s) ".ljust(79, "=")} | |
block_helper(begin_msg, ensure_msg) {yield} | |
end | |
def stage action, name | |
begin_msg = -> start {"-- #{action}(:#{name})"} | |
ensure_msg = -> start {" -> #{Time.now.minus_with_coercion(start).round(4)}s"} | |
block_helper(begin_msg, ensure_msg) {yield} | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment