Module: ShopifyToolkit::Migration::Logging
- Included in:
- ShopifyToolkit::MetafieldStatements, ShopifyToolkit::MetaobjectStatements, ShopifyToolkit::Migration, Schema
- Defined in:
- lib/shopify_toolkit/migration/logging.rb
Instance Method Summary collapse
- #announce(message) ⇒ Object
-
#say(message, subitem = false) ⇒ Object
Takes a message argument and outputs it as is.
-
#say_with_time(message) ⇒ Object
Outputs text along with how long it took to run its block.
- #write(text = "") ⇒ Object
Instance Method Details
#announce(message) ⇒ Object
8 9 10 11 |
# File 'lib/shopify_toolkit/migration/logging.rb', line 8 def announce() length = [0, 75 - .length].max write "== %s %s" % [, "=" * length] end |
#say(message, subitem = false) ⇒ Object
Takes a message argument and outputs it as is. A second boolean argument can be passed to specify whether to indent or not.
15 16 17 |
# File 'lib/shopify_toolkit/migration/logging.rb', line 15 def say(, subitem = false) write "#{subitem ? " ->" : "--"} #{}" end |
#say_with_time(message) ⇒ Object
Outputs text along with how long it took to run its block. If the block returns an integer it assumes it is the number of rows affected.
21 22 23 24 25 26 27 |
# File 'lib/shopify_toolkit/migration/logging.rb', line 21 def say_with_time() say() result = nil time_elapsed = ActiveSupport::Benchmark.realtime { result = yield } say "%.4fs" % time_elapsed, :subitem result end |
#write(text = "") ⇒ Object
4 5 6 |
# File 'lib/shopify_toolkit/migration/logging.rb', line 4 def write(text = "") puts(text) end |