Class: JSONAPI::Utils::Exceptions::ActiveRecord
- Inherits:
-
Exceptions::Error
- Object
- Exceptions::Error
- JSONAPI::Utils::Exceptions::ActiveRecord
- Defined in:
- lib/jsonapi/utils/exceptions/active_record.rb
Instance Attribute Summary collapse
-
#foreign_keys ⇒ Object
readonly
Returns the value of attribute foreign_keys.
-
#object ⇒ Object
readonly
Returns the value of attribute object.
-
#relationship_names ⇒ Object
readonly
Returns the value of attribute relationship_names.
-
#relationships ⇒ Object
readonly
Returns the value of attribute relationships.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Instance Method Summary collapse
-
#errors ⇒ Array
Decorate errors for AR invalid objects.
-
#initialize(object, resource_klass, context) ⇒ JSONAPI::Utils::Exceptions::ActiveRecord
constructor
Construct an error decorator over ActiveRecord objects.
Constructor Details
#initialize(object, resource_klass, context) ⇒ JSONAPI::Utils::Exceptions::ActiveRecord
Construct an error decorator over ActiveRecord objects.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/jsonapi/utils/exceptions/active_record.rb', line 18 def initialize(object, resource_klass, context) @object = object @resource = resource_klass.new(object, context) # Need to reflect on resource's relationships for error reporting. @relationships = resource_klass._relationships.values @relationship_names = @relationships.map(&:name).map(&:to_sym) @foreign_keys = @relationships.map(&:foreign_key).map(&:to_sym) @resource_key_for = {} @formatted_key = {} end |
Instance Attribute Details
#foreign_keys ⇒ Object (readonly)
Returns the value of attribute foreign_keys.
5 6 7 |
# File 'lib/jsonapi/utils/exceptions/active_record.rb', line 5 def foreign_keys @foreign_keys end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
5 6 7 |
# File 'lib/jsonapi/utils/exceptions/active_record.rb', line 5 def object @object end |
#relationship_names ⇒ Object (readonly)
Returns the value of attribute relationship_names.
5 6 7 |
# File 'lib/jsonapi/utils/exceptions/active_record.rb', line 5 def relationship_names @relationship_names end |
#relationships ⇒ Object (readonly)
Returns the value of attribute relationships.
5 6 7 |
# File 'lib/jsonapi/utils/exceptions/active_record.rb', line 5 def relationships @relationships end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
5 6 7 |
# File 'lib/jsonapi/utils/exceptions/active_record.rb', line 5 def resource @resource end |
Instance Method Details
#errors ⇒ Array
Note:
That’s the method used by formatters to build the response’s error body.
Decorate errors for AR invalid objects.
37 38 39 40 41 42 43 |
# File 'lib/jsonapi/utils/exceptions/active_record.rb', line 37 def errors object.errors..flat_map do |field, | .map.with_index do |, index| build_error(field, , index) end end end |