Class: JSONAPI::Utils::Exceptions::ActiveRecord
- Inherits:
-
Exceptions::Error
- Object
- Exceptions::Error
- JSONAPI::Utils::Exceptions::ActiveRecord
- Defined in:
- lib/jsonapi/utils/exceptions.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_keys ⇒ Object
readonly
Returns the value of attribute relationship_keys.
-
#relationships ⇒ Object
readonly
Returns the value of attribute relationships.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Instance Method Summary collapse
- #errors ⇒ Object
-
#initialize(object, resource_klass, context) ⇒ ActiveRecord
constructor
A new instance of ActiveRecord.
Constructor Details
#initialize(object, resource_klass, context) ⇒ ActiveRecord
Returns a new instance of ActiveRecord.
9 10 11 12 13 14 15 16 17 |
# File 'lib/jsonapi/utils/exceptions.rb', line 9 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_keys = @relationships.map(&:name).map(&:to_sym) @foreign_keys = @relationships.map(&:foreign_key).map(&:to_sym) end |
Instance Attribute Details
#foreign_keys ⇒ Object (readonly)
Returns the value of attribute foreign_keys.
7 8 9 |
# File 'lib/jsonapi/utils/exceptions.rb', line 7 def foreign_keys @foreign_keys end |
#object ⇒ Object (readonly)
Returns the value of attribute object.
7 8 9 |
# File 'lib/jsonapi/utils/exceptions.rb', line 7 def object @object end |
#relationship_keys ⇒ Object (readonly)
Returns the value of attribute relationship_keys.
7 8 9 |
# File 'lib/jsonapi/utils/exceptions.rb', line 7 def relationship_keys @relationship_keys end |
#relationships ⇒ Object (readonly)
Returns the value of attribute relationships.
7 8 9 |
# File 'lib/jsonapi/utils/exceptions.rb', line 7 def relationships @relationships end |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
7 8 9 |
# File 'lib/jsonapi/utils/exceptions.rb', line 7 def resource @resource end |
Instance Method Details
#errors ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/jsonapi/utils/exceptions.rb', line 19 def errors object.errors..flat_map do |key, | .map do || = error_base .merge(title: title_member(key, )) .merge(id: id_member(key)) .merge(source_member(key)) JSONAPI::Error.new() end end end |