Class: WarningSigns::Behavior::Base

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

Direct Known Subclasses

Ignore, Log, Raise, Stderr, Stdout

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, backtrace, message_formatter) ⇒ Base

Returns a new instance of Base.



11
12
13
14
15
# File 'lib/warning_signs/behavior/base.rb', line 11

def initialize(message, backtrace, message_formatter)
  @message = message
  @backtrace = backtrace
  @message_formatter = message_formatter
end

Instance Attribute Details

#backtraceObject (readonly)

Returns the value of attribute backtrace.



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

def backtrace
  @backtrace
end

#messageObject (readonly)

Returns the value of attribute message.



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

def message
  @message
end

#message_formatterObject (readonly)

Returns the value of attribute message_formatter.



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

def message_formatter
  @message_formatter
end

Class Method Details

.for(behavior_type, *args) ⇒ Object



6
7
8
9
# File 'lib/warning_signs/behavior/base.rb', line 6

def self.for(behavior_type, *args)
  class_name = "WarningSigns::Behavior::#{behavior_type.classify}"
  class_name.constantize.new(*args)
end

Instance Method Details

#emitObject

Raises:

  • (NotImplementedError)


23
24
25
# File 'lib/warning_signs/behavior/base.rb', line 23

def emit
  raise NotImplementedError
end

#formatted_messageObject



17
18
19
20
21
# File 'lib/warning_signs/behavior/base.rb', line 17

def formatted_message
  result = message_formatter.format_message(message, backtrace)
  result = [result] unless result.is_a?(Array)
  result
end