Class: SimpleJsonapi::Errors::ActiveModelError

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attribute, message, pointer) ⇒ ActiveModelError

Returns a new instance of ActiveModelError.



14
15
16
17
18
# File 'lib/simple_jsonapi/errors/active_model_error.rb', line 14

def initialize(attribute, message, pointer)
  @attribute = attribute.to_s
  @message = message.to_s
  @pointer = pointer.to_s
end

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



12
13
14
# File 'lib/simple_jsonapi/errors/active_model_error.rb', line 12

def attribute
  @attribute
end

#messageObject (readonly)

Returns the value of attribute message.



12
13
14
# File 'lib/simple_jsonapi/errors/active_model_error.rb', line 12

def message
  @message
end

#pointerObject (readonly)

Returns the value of attribute pointer.



12
13
14
# File 'lib/simple_jsonapi/errors/active_model_error.rb', line 12

def pointer
  @pointer
end

Class Method Details

.from_errors(errors, pointer_mapping = {}) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/simple_jsonapi/errors/active_model_error.rb', line 4

def self.from_errors(errors, pointer_mapping = {})
  errors.keys.flat_map do |attribute|
    errors.full_messages_for(attribute).map do |message|
      new(attribute, message, pointer_mapping[attribute])
    end
  end
end