Sha256: e2ccf3cf8ee0b75e193be2f3379b789c3d5494da10b2bb25bc2adb9e400390e2

Contents?: true

Size: 1.02 KB

Versions: 7

Compression:

Stored size: 1.02 KB

Contents

module WarningSigns
  class World
    include Singleton
    attr_accessor :handlers

    def self.from_file(filename)
      from_hash(YAML.load_file(filename))
    end

    def self.from_hash(hash)
      instance.clear
      instance.handlers = hash["handlers"].map { Handler.from_hash(_1) }
      instance.one_time_set_up
      instance
    end

    def initialize
      @initialized = false
      clear
    end

    def handler_for(deprecation)
      handlers.find { _1.match?(deprecation) }
    end

    def clear
      @handlers = []
    end

    def enabled_for_rails?
      handlers.any? { !_1.enabled_for_rails? }
    end

    def enabled_for_ruby?
      handlers.any? { !_1.enabled_for_ruby? }
    end

    def one_time_set_up
      return if @initialized
      ruby_set_up
      rails_set_up
      @initialized = true
    end

    def ruby_set_up
      Warning[:deprecated] = true
      Warning.extend(WarningSigns::RubyDeprecationCatcher)
    end

    def rails_set_up
      ActiveSupport::Deprecation.behavior = :notify
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
warning_signs-0.6.1 lib/warning_signs/world.rb
warning_signs-0.6.0 lib/warning_signs/world.rb
warning_signs-0.5.0 lib/warning_signs/world.rb
warning_signs-0.4.0 lib/warning_signs/world.rb
warning_signs-0.3.0 lib/warning_signs/world.rb
warning_signs-0.1.0 lib/warning_signs/world.rb
warning_signs-0.0.1 lib/warning_signs/world.rb