Class: MetaInspector::ExceptionLog

Inherits:
Object
  • Object
show all
Defined in:
lib/meta_inspector/exception_log.rb

Overview

Stores the exceptions passed to it, warning about them if required

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ ExceptionLog

Returns a new instance of ExceptionLog.



7
8
9
10
# File 'lib/meta_inspector/exception_log.rb', line 7

def initialize(options = {})
  @warn_level = options[:warn_level] || :raise
  @exceptions = []
end

Instance Attribute Details

#exceptionsObject (readonly)

Returns the value of attribute exceptions.



5
6
7
# File 'lib/meta_inspector/exception_log.rb', line 5

def exceptions
  @exceptions
end

#warn_levelObject (readonly)

Returns the value of attribute warn_level.



5
6
7
# File 'lib/meta_inspector/exception_log.rb', line 5

def warn_level
  @warn_level
end

Instance Method Details

#<<(exception) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/meta_inspector/exception_log.rb', line 12

def <<(exception)
  case warn_level
  when :raise
    fail exception
  when :warn
    warn exception
  when :store
    @exceptions << exception
  end
end

#ok?Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
# File 'lib/meta_inspector/exception_log.rb', line 23

def ok?
  if warn_level == :store
    exceptions.empty?
  else
    warn 'ExceptionLog#ok? should only be used when warn_level is :store'
  end
end