class Importer::Error
Attributes
column[R]
row[R]
text[R]
value[R]
Public Class Methods
context_column()
click to toggle source
# File lib/iron/import/error.rb, line 41 def self.context_column @context_column end
context_row()
click to toggle source
# File lib/iron/import/error.rb, line 37 def self.context_row @context_row end
context_value()
click to toggle source
# File lib/iron/import/error.rb, line 45 def self.context_value @context_value end
error_occurred!()
click to toggle source
# File lib/iron/import/error.rb, line 49 def self.error_occurred! @error_occurred = true end
new(text, context = {})
click to toggle source
# File lib/iron/import/error.rb, line 53 def initialize(text, context = {}) @text = text.to_s @row = context[:row] || Error.context_row @column = context[:column] || Error.context_column @value = context[:value] || Error.context_value @row.errors << self if @row @column.errors << self if @column Error.error_occurred! end
with_context(importer, row, column, val) { || ... }
click to toggle source
Block wrapper to set error context for any errors generated within the block
# File lib/iron/import/error.rb, line 8 def self.with_context(importer, row, column, val) # Set new context old_row = @context_row @context_row = row old_col = @context_column @context_column = column old_val = @context_value @context_value = val old_err = @error_occurred @error_occurred = false # Run the block, catch raised exceptions as errors begin yield rescue RuntimeError => e # Old-style way of registering errors was to just raise 'foo' importer.add_exception(e) end had_error = @error_occurred # Reset to old context @context_row = old_row @context_column = old_col @context_value = old_val @error_occurred = old_err return had_error end
Public Instance Methods
for_context?(context)
click to toggle source
importer_level?()
click to toggle source
# File lib/iron/import/error.rb, line 88 def importer_level? level == :importer end
level()
click to toggle source
Returns the level at which this error occurred, one of :row, :importer
# File lib/iron/import/error.rb, line 79 def level return :row if @row return :importer end
row_level?()
click to toggle source
# File lib/iron/import/error.rb, line 84 def row_level? level == :row end
summary()
click to toggle source
# File lib/iron/import/error.rb, line 65 def summary summary = '' if @row summary += "#{@row}: " end summary + @text end
to_s()
click to toggle source
# File lib/iron/import/error.rb, line 73 def to_s summary end