Skip to content

Instantly share code, notes, and snippets.

@amancevice
Created December 3, 2016 20:02
Show Gist options
  • Save amancevice/fd10dc533d80ceab255213dd8f7f366a to your computer and use it in GitHub Desktop.
Save amancevice/fd10dc533d80ceab255213dd8f7f366a to your computer and use it in GitHub Desktop.
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