Sha256: 4f8b137e434767f7f51f13cc948a433b940b88f75f1625d20d087bf6a9f356b8

Contents?: true

Size: 1.17 KB

Versions: 2

Compression:

Stored size: 1.17 KB

Contents

require_relative "warner/version"

if Object.const_defined?('ActiveSupport')
  module ActiveSupport
    class Deprecation
      DEFAULT_BEHAVIORS[:stderr] = -> (message, callstack) {
        $stderr.puts"\e[41;37;1m#{message}\e[0m"
        $stderr.puts callstack.join("\n  ") if debug
      }
    end
  end
end

class Warner

  def self.colored_warning(message, callstack = nil)
    if Object.const_defined?('ActiveSupport')
      # callstack ||= caller_locations(2)
      ActiveSupport::Deprecation.warn message, callstack
    else
      warn "\e[41;37;1m[DEPRECATION WARNING]: #{message}\e[0m"
    end
  end

  def self.rails_version_warning(version, message)
    if Object.const_defined?('Rails')
      if Gem::Version.new(Rails.version) > Gem::Version.new(version)
        colored_warning "[RAILS] %s > %s : %s" % [Rails.version, version, message], caller
      end
    else
      raise "Rails not loaded"
    end
  end

  def self.gem_version_warning(gem_name, version, message)
    if Gem.loaded_specs[gem_name].version > Gem::Version.new(version)
      colored_warning "[gem:%s] %s > %s : %s" % [gem_name, Gem.loaded_specs[gem_name].version, version, message], caller
    end
  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
warner-1.0.1 lib/warner.rb
warner-1.0.0 lib/warner.rb