Class: Schema::Errors

Inherits:
Object
  • Object
show all
Defined in:
lib/schema/errors.rb

Overview

Schema::Errors used internally for testing mainly, recommend using ActiveModel::Validations

Constant Summary collapse

EMPTY_ARRAY =
[].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeErrors

Returns a new instance of Errors.



10
11
12
# File 'lib/schema/errors.rb', line 10

def initialize
  @errors = {}
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



6
7
8
# File 'lib/schema/errors.rb', line 6

def errors
  @errors
end

Instance Method Details

#[](name) ⇒ Object



14
15
16
# File 'lib/schema/errors.rb', line 14

def [](name)
  @errors[name] || EMPTY_ARRAY
end

#add(name, error) ⇒ Object Also known as: []=



18
19
20
21
# File 'lib/schema/errors.rb', line 18

def add(name, error)
  @errors[name] ||= []
  @errors[name] << error
end

#empty?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/schema/errors.rb', line 24

def empty?
  @errors.empty?
end