Class: Jsapi::Model::NestedError
- Inherits:
-
Object
- Object
- Jsapi::Model::NestedError
- Defined in:
- lib/jsapi/model/nested_error.rb
Overview
Wraps an error related to a nested model.
Instance Attribute Summary collapse
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
Instance Method Summary collapse
-
#==(other) ⇒ Object
:nodoc:.
-
#full_message ⇒ Object
Like
ActiveModel::Error#full_message
. -
#initialize(attribute, error) ⇒ NestedError
constructor
A new instance of NestedError.
-
#match?(attribute, type = nil, **options) ⇒ Boolean
Like
ActiveModel::Error#match?
. -
#message ⇒ Object
Like
ActiveModel::Error#message
. -
#strict_match?(attribute, type = nil, **options) ⇒ Boolean
Like
ActiveModel::Error#strict_match?
.
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
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
7 8 9 |
# File 'lib/jsapi/model/nested_error.rb', line 7 def attribute @attribute end |
#error ⇒ Object (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_message ⇒ Object
Like ActiveModel::Error#full_message
.
23 24 25 |
# File 'lib/jsapi/model/nested_error.rb', line 23 def base? ? "'#{attribute}' #{}" : "'#{attribute}.#{[1..]}" end |
#match?(attribute, type = nil, **options) ⇒ Boolean
Like ActiveModel::Error#match?
.
28 29 30 31 32 33 |
# File 'lib/jsapi/model/nested_error.rb', line 28 def match?(attribute, type = nil, **) return false if self.attribute != attribute return true if type.nil? && .empty? @error.match?(:base, type, **) end |
#message ⇒ Object
Like ActiveModel::Error#message
.
36 37 38 |
# File 'lib/jsapi/model/nested_error.rb', line 36 def base? ? @error. : "'#{@error.attribute}' #{@error.}".rstrip end |
#strict_match?(attribute, type = nil, **options) ⇒ Boolean
Like ActiveModel::Error#strict_match?
.
41 42 43 44 45 |
# File 'lib/jsapi/model/nested_error.rb', line 41 def strict_match?(attribute, type = nil, **) return false unless match?(attribute, type, **) @error.strict_match?(:base, type, **) end |