Sha256: bb6aada6319773d728acca195c043778694868c1022ac7e5ab5cf798016eb781

Contents?: true

Size: 1.01 KB

Versions: 66

Compression:

Stored size: 1.01 KB

Contents

require 'active_record/migration'

class ActiveRecord::Migration
  cattr_accessor :time_recorder
  cattr_accessor :disable_logging

  def write_with_logging(text = '')
    logger = Ridgepole::Logger.instance
    logger.info(text) unless self.disable_logging
    parse_text(text)
  end
  alias_method_chain :write, :logging

  def parse_text(text)
    return unless self.time_recorder

    case text
    when /\A--\s+(.+)\Z/
      self.time_recorder.add_key($1)
    when /\A\s+->\s+(\d+\.\d+)s\Z/
      self.time_recorder.add_value($1.to_f)
    end
  end

  def self.record_time
    result = nil

    begin
      self.time_recorder = TimeRecorder.new
      yield
      result = self.time_recorder.result
    ensure
      self.time_recorder = nil
    end

    return result
  end

  class TimeRecorder
    attr_reader :result

    def initialize
      @result = {}
    end

    def add_key(key)
      @key = key
    end

    def add_value(value)
      if @key
        @result[@key] = value
      end

      @key = nil
    end
  end
end

Version data entries

66 entries across 66 versions & 1 rubygems

Version Path
ridgepole-0.6.4.beta5 lib/ridgepole/migration_ext.rb
ridgepole-0.6.4.beta4 lib/ridgepole/migration_ext.rb
ridgepole-0.6.4.beta3 lib/ridgepole/migration_ext.rb
ridgepole-0.6.4.beta2 lib/ridgepole/migration_ext.rb
ridgepole-0.6.4.beta lib/ridgepole/migration_ext.rb
ridgepole-0.6.3 lib/ridgepole/migration_ext.rb
ridgepole-0.6.3.beta5 lib/ridgepole/migration_ext.rb
ridgepole-0.6.3.beta4 lib/ridgepole/migration_ext.rb
ridgepole-0.6.3.beta3 lib/ridgepole/migration_ext.rb
ridgepole-0.6.3.beta2 lib/ridgepole/migration_ext.rb
ridgepole-0.6.3.beta lib/ridgepole/migration_ext.rb
ridgepole-0.6.2 lib/ridgepole/migration_ext.rb
ridgepole-0.6.2.beta lib/ridgepole/migration_ext.rb
ridgepole-0.6.1 lib/ridgepole/migration_ext.rb
ridgepole-0.6.1.beta2 lib/ridgepole/migration_ext.rb
ridgepole-0.6.1.beta lib/ridgepole/migration_ext.rb
ridgepole-0.6.0 lib/ridgepole/migration_ext.rb
ridgepole-0.6.0.beta5 lib/ridgepole/migration_ext.rb
ridgepole-0.6.0.beta4 lib/ridgepole/migration_ext.rb
ridgepole-0.5.3.beta4 lib/ridgepole/migration_ext.rb