Class: SimpleJsonapi::Node::Errors
- Defined in:
- lib/simple_jsonapi/node/errors.rb
Instance Attribute Summary collapse
- #errors ⇒ Array<Object> readonly
Attributes inherited from Base
#extras, #fields_spec, #include_spec, #root_node, #serializer, #serializer_inferrer, #sort_spec
Instance Method Summary collapse
- #as_jsonapi ⇒ Hash{Symbol => Hash}
-
#initialize(errors:, **options) ⇒ Errors
constructor
A new instance of Errors.
Constructor Details
#initialize(errors:, **options) ⇒ Errors
Returns a new instance of Errors.
9 10 11 12 13 14 15 16 17 |
# File 'lib/simple_jsonapi/node/errors.rb', line 9 def initialize(errors:, **) super() @errors = Array.wrap(errors) @error_nodes = @errors.map do |error| build_child_node(SimpleJsonapi::Node::Error, error: error) end end |
Instance Attribute Details
#errors ⇒ Array<Object> (readonly)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/simple_jsonapi/node/errors.rb', line 4 class Errors < Base attr_reader :errors # @param errors [Array<Object>] # @param options see {Node::Base#initialize} for additional parameters def initialize(errors:, **) super() @errors = Array.wrap(errors) @error_nodes = @errors.map do |error| build_child_node(SimpleJsonapi::Node::Error, error: error) end end # @return [Hash{Symbol => Hash}] def as_jsonapi if @error_nodes.any? { errors: @error_nodes.map(&:as_jsonapi) } else {} end end end |
Instance Method Details
#as_jsonapi ⇒ Hash{Symbol => Hash}
20 21 22 23 24 25 26 |
# File 'lib/simple_jsonapi/node/errors.rb', line 20 def as_jsonapi if @error_nodes.any? { errors: @error_nodes.map(&:as_jsonapi) } else {} end end |