Class: Rumx::Beans::Error

Inherits:
Object
  • Object
show all
Includes:
Rumx::Bean
Defined in:
lib/rumx/beans/error.rb

Instance Method Summary collapse

Methods included from Rumx::Bean

#bean_add_child, #bean_children, #bean_each, #bean_each_child, #bean_each_child_recursive, #bean_each_embedded_child, #bean_each_operation, #bean_each_operation_recursive, #bean_embedded, #bean_find, #bean_get_and_set_attributes, #bean_get_attributes, #bean_has_attributes?, #bean_has_operations?, #bean_monitor, #bean_remove_child, #bean_set_and_get_attributes, #bean_set_attributes, #bean_synchronize, find, find_attribute, find_operation, included, root

Constructor Details

#initialize(opts = {}) ⇒ Error

Returns a new instance of Error.



9
10
11
12
# File 'lib/rumx/beans/error.rb', line 9

def initialize(opts={})
  @errors = []
  @max_errors = (opts[:max_errors] || 1).to_i
end

Instance Method Details

#perform(prefix = '') ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/rumx/beans/error.rb', line 20

def perform(prefix='')
  yield
rescue Exception => e
  bean_synchronize do
    @error_count += 1
    @errors << Message.new(e.message)
    @errors.shift while @errors.size > @max_errors
  end
  raise
end

#reset=(val) ⇒ Object



14
15
16
17
18
# File 'lib/rumx/beans/error.rb', line 14

def reset=(val)
  if val
    @error_count = 0
  end
end

#to_sObject



31
32
33
# File 'lib/rumx/beans/error.rb', line 31

def to_s
  "error_count=#{@error_count} last_error=#{@errors.last}"
end