class Cuprum::Collections::Errors::ExtraAttributes

Error returned when assigning invalid attributes to an entity.

Constants

TYPE

Short string used to identify the type of error.

Attributes

entity_class[R]

@return [Class] the class of the assigned entity.

extra_attributes[R]

@return [Array<String>] The names of the extra attributes that were

assigned to the entity.
valid_attributes[R]

@return [Array<String>] The names of valid attributes for the entity.

Public Class Methods

new(entity_class:, extra_attributes:, valid_attributes:) click to toggle source

@param entity_class [Class] The class of the assigned entity. @param extra_attributes [Array<String>] The names of the extra attributes

that were assigned to the entity.

@param valid_attributes [Array<String>] The names of valid attributes for

the entity.
Calls superclass method
# File lib/cuprum/collections/errors/extra_attributes.rb, line 18
def initialize(entity_class:, extra_attributes:, valid_attributes:)
  @entity_class     = entity_class
  @extra_attributes = extra_attributes
  @valid_attributes = valid_attributes

  super(
    entity_class:     entity_class,
    extra_attributes: extra_attributes,
    message:          default_message,
    valid_attributes: valid_attributes
  )
end

Public Instance Methods

as_json() click to toggle source

@return [Hash] a serializable hash representation of the error.

# File lib/cuprum/collections/errors/extra_attributes.rb, line 42
def as_json
  {
    'data'    => {
      'entity_class'     => entity_class.name,
      'extra_attributes' => extra_attributes,
      'valid_attributes' => valid_attributes
    },
    'message' => message,
    'type'    => type
  }
end
type() click to toggle source

@return [String] short string used to identify the type of error.

# File lib/cuprum/collections/errors/extra_attributes.rb, line 55
def type
  TYPE
end

Private Instance Methods

default_message() click to toggle source
# File lib/cuprum/collections/errors/extra_attributes.rb, line 61
def default_message
  "invalid attributes for #{entity_class.name}:" \
    " #{extra_attributes.join(', ')}"
end