Class: WarningSigns::World

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/warning_signs/world.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWorld

Returns a new instance of World.



17
18
19
20
# File 'lib/warning_signs/world.rb', line 17

def initialize
  @initialized = false
  clear
end

Instance Attribute Details

#handlersObject

Returns the value of attribute handlers.



4
5
6
# File 'lib/warning_signs/world.rb', line 4

def handlers
  @handlers
end

Class Method Details

.from_file(filename) ⇒ Object



6
7
8
# File 'lib/warning_signs/world.rb', line 6

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

.from_hash(hash) ⇒ Object



10
11
12
13
14
15
# File 'lib/warning_signs/world.rb', line 10

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

Instance Method Details

#clearObject



26
27
28
# File 'lib/warning_signs/world.rb', line 26

def clear
  @handlers = []
end

#enabled_for_rails?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/warning_signs/world.rb', line 30

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

#enabled_for_ruby?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/warning_signs/world.rb', line 34

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

#handler_for(deprecation) ⇒ Object



22
23
24
# File 'lib/warning_signs/world.rb', line 22

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

#one_time_set_upObject



38
39
40
41
42
43
# File 'lib/warning_signs/world.rb', line 38

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

#rails_set_upObject



50
51
52
53
54
55
56
# File 'lib/warning_signs/world.rb', line 50

def rails_set_up
  if ActiveSupport.version >= Gem::Version.new("7.1.0")
    Rails.application.deprecators.behavior = :notify
  else
    ActiveSupport::Deprecation.behavior = :notify
  end
end

#ruby_set_upObject



45
46
47
48
# File 'lib/warning_signs/world.rb', line 45

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