method

say_with_time

rails latest stable - Class: ActiveRecord::Migration

Method deprecated or moved

This method is deprecated or moved on the latest stable version. The last existing version (v3.0.9) is shown here.

say_with_time(message)
public

No documentation available.

# File activerecord/lib/active_record/migration.rb, line 358
      def say_with_time(message)
        say(message)
        result = nil
        time = Benchmark.measure { result = yield }
        say "%.4fs" % time.real, :subitem
        say("#{result} rows", :subitem) if result.is_a?(Integer)
        result
      end

2Notes

print standard-looking messages during migration

metavida · Sep 16, 20088 thanks

Within a migration file you can use the say_with_time method to print out informational messages that match the style of standard migration messages. See the say method also.

say_with_time "migrate existing data" do
# ... execute migration sql ...
end
#=> "-- migrate existing data"
#=> "   -> 0.0299s"

Include items affected in output

rab · Nov 17, 2014

If the result returned from the block is an Integer, the output will include a message about that number of "rows" in addition to the elapsed time.

say_with_time "Some complex, custom work" do
counter = 0
# ... do some stuff here that increments the counter ...
counter
end

#=> "-- Some complex, custom work"
#=> "   -> 45.3725s"
#=> "   -> 52880 rows"