class SmartCore::Validator::ErrorSet
@api private @since 0.1.0
Attributes
errors[R]
@return [Array<Symbol>]
@api private @since 0.1.0
Public Class Methods
new()
click to toggle source
@return [void]
@api private @since 0.1.0
# File lib/smart_core/validator/error_set.rb, line 11 def initialize @errors = Set.new @access_lock = Mutex.new end
Public Instance Methods
add_error(error_code)
click to toggle source
@param error_codes [Arrray<Symbol>] @return [void]
@api private @since 0.1.0
# File lib/smart_core/validator/error_set.rb, line 21 def add_error(error_code) thread_safe { store_error(error_code) } end
clear()
click to toggle source
@return [void]
@api private @since 0.1.0
# File lib/smart_core/validator/error_set.rb, line 50 def clear thread_safe { errors.clear } end
codes()
click to toggle source
@return [Array<Symbol>]
@api private @since 0.1.0
# File lib/smart_core/validator/error_set.rb, line 58 def codes thread_safe { errors.to_a } end
concat(error_set)
click to toggle source
@param error_set [SmartCore::Validator::ErrorSet] @return [void]
@api private @since 0.1.0
# File lib/smart_core/validator/error_set.rb, line 30 def concat(error_set) thread_safe do error_set.codes.each do |error_code| store_error(error_code) end end end
empty?()
click to toggle source
@return [Boolean]
@api private @since 0.1.0
# File lib/smart_core/validator/error_set.rb, line 42 def empty? thread_safe { errors.empty? } end
Private Instance Methods
store_error(error_code)
click to toggle source
@param error_code [Symbol, String] @return [void]
@raise [SmartCore::Validator::IncorrectErrorCodeError]
@api private @since 0.1.0
# File lib/smart_core/validator/error_set.rb, line 77 def store_error(error_code) # NOTE: think about the any type of error codes unless error_code.is_a?(Symbol) || error_code.is_a?(String) raise IncorrectErrorCodeError, 'Error code should be a symbol or a string' end errors << error_code.to_sym end
thread_safe(&block)
click to toggle source
@param block [Proc] @return [Any]
@api private @since 0.1.0
# File lib/smart_core/validator/error_set.rb, line 91 def thread_safe(&block) @access_lock.synchronize(&block) end