Class: WarningSigns::Deprecation

Inherits:
Object
  • Object
show all
Defined in:
lib/warning_signs/deprecation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, source:, category: nil, backtrace: []) ⇒ Deprecation

Returns a new instance of Deprecation.



5
6
7
8
9
10
# File 'lib/warning_signs/deprecation.rb', line 5

def initialize(message, source:, category: nil, backtrace: [])
  @message = message
  @source = source.to_s.downcase.inquiry
  @category = category
  @backtrace = backtrace || []
end

Instance Attribute Details

#backtraceObject

Returns the value of attribute backtrace.



3
4
5
# File 'lib/warning_signs/deprecation.rb', line 3

def backtrace
  @backtrace
end

#categoryObject

Returns the value of attribute category.



3
4
5
# File 'lib/warning_signs/deprecation.rb', line 3

def category
  @category
end

#messageObject

Returns the value of attribute message.



3
4
5
# File 'lib/warning_signs/deprecation.rb', line 3

def message
  @message
end

#sourceObject

Returns the value of attribute source.



3
4
5
# File 'lib/warning_signs/deprecation.rb', line 3

def source
  @source
end

Instance Method Details

#behaviorsObject

force raise to be the last element if it is present



21
22
23
24
25
# File 'lib/warning_signs/deprecation.rb', line 21

def behaviors
  result = (handler&.environment&.behaviors || []).inquiry
  return result unless result.raise?
  (result - ["raise"]) << "raise"
end

#handlerObject



12
13
14
# File 'lib/warning_signs/deprecation.rb', line 12

def handler
  World.instance.handler_for(self)
end

#invokeObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/warning_signs/deprecation.rb', line 27

def invoke
  behaviors.each do |behavior_type|
    Behavior::Base.for(
      behavior_type,
      message,
      backtrace,
      message_formatter_for(behavior_type)
    ).emit
  end
end

#message_formatter_for(behavior) ⇒ Object



16
17
18
# File 'lib/warning_signs/deprecation.rb', line 16

def message_formatter_for(behavior)
  handler.message_formatter_for(behavior)
end