Class: Jsapi::Model::NestedError

Inherits:
Object
  • Object
show all
Defined in:
lib/jsapi/model/nested_error.rb

Overview

Wraps an error related to a nested model.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute, error) ⇒ NestedError

Returns a new instance of NestedError.



11
12
13
14
# File 'lib/jsapi/model/nested_error.rb', line 11

def initialize(attribute, error)
  @attribute = attribute
  @error = error
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



7
8
9
# File 'lib/jsapi/model/nested_error.rb', line 7

def attribute
  @attribute
end

#errorObject (readonly)

Returns the value of attribute error.



7
8
9
# File 'lib/jsapi/model/nested_error.rb', line 7

def error
  @error
end

Instance Method Details

#==(other) ⇒ Object

:nodoc:



16
17
18
19
20
# File 'lib/jsapi/model/nested_error.rb', line 16

def ==(other) # :nodoc:
  other.is_a?(self.class) &&
    @attribute == other.attribute &&
    @error == other.error
end

#full_messageObject

Like ActiveModel::Error#full_message.



23
24
25
# File 'lib/jsapi/model/nested_error.rb', line 23

def full_message
  base? ? "'#{attribute}' #{message}" : "'#{attribute}.#{message[1..]}"
end

#match?(attribute, type = nil, **options) ⇒ Boolean

Like ActiveModel::Error#match?.

Returns:

  • (Boolean)


28
29
30
31
32
33
# File 'lib/jsapi/model/nested_error.rb', line 28

def match?(attribute, type = nil, **options)
  return false if self.attribute != attribute
  return true if type.nil? && options.empty?

  @error.match?(:base, type, **options)
end

#messageObject

Like ActiveModel::Error#message.



36
37
38
# File 'lib/jsapi/model/nested_error.rb', line 36

def message
  base? ? @error.message : "'#{@error.attribute}' #{@error.message}".rstrip
end

#strict_match?(attribute, type = nil, **options) ⇒ Boolean

Like ActiveModel::Error#strict_match?.

Returns:

  • (Boolean)


41
42
43
44
45
# File 'lib/jsapi/model/nested_error.rb', line 41

def strict_match?(attribute, type = nil, **options)
  return false unless match?(attribute, type, **options)

  @error.strict_match?(:base, type, **options)
end