Class: Wardrobe::Plugins::Validation::ErrorStore

Inherits:
Object
  • Object
show all
Defined in:
lib/wardrobe/plugins/validation/error_store.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeErrorStore

Returns a new instance of ErrorStore.



10
11
12
# File 'lib/wardrobe/plugins/validation/error_store.rb', line 10

def initialize
  @store = Hash.new { |hash, key| hash[key] = Array.new }
end

Instance Attribute Details

#storeObject (readonly)

Returns the value of attribute store.



7
8
9
# File 'lib/wardrobe/plugins/validation/error_store.rb', line 7

def store
  @store
end

Instance Method Details

#add(atr, *errors) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/wardrobe/plugins/validation/error_store.rb', line 14

def add(atr, *errors)
  errors.each do |error|
    if error.is_a? String
      @store[atr.name] << error
    else
      @store[atr.name].unshift({}) unless @store[atr.name].first.is_a?(Hash)
      @store[atr.name].first.deep_merge!(error)
    end
  end
end