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

Instance Method Details

#announce(message) ⇒ Object



8
9
10
11
# File 'lib/shopify_toolkit/migration/logging.rb', line 8

def announce(message)
  length = [0, 75 - message.length].max
  write "== %s %s" % [message, "=" * 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(message, subitem = false)
  write "#{subitem ? "   ->" : "--"} #{message}"
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(message)
  say(message)
  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