Class: JSONAPIonify::Structure::Objects::TopLevel

Inherits:
Base
  • Object
show all
Defined in:
lib/jsonapionify/structure/objects/top_level.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#errors, #object, #parent, #warnings

Instance Method Summary collapse

Methods inherited from Base

#==, #===, #as_json, #compile!, #copy, define_order, from_hash, from_json, #initialize, #inspect, #pretty_json, #signature, #to_h, #to_json, #validate

Methods included from Helpers::ObjectDefaults

#[], #[]=

Methods included from Helpers::Validations

#allowed_type_map, #permitted_key?, #permitted_keys, #permitted_type_for?, #permitted_types_for, #required_key?, #required_keys

Methods included from Helpers::ObjectSetters

#[], #[]=

Methods included from Helpers::InheritsOrigin

#client?, #server?

Methods included from Callbacks

#run_callbacks

Constructor Details

This class inherits a constructor from JSONAPIonify::Structure::Objects::Base

Instance Attribute Details

#originObject (readonly)

Returns the value of attribute origin.



9
10
11
# File 'lib/jsonapionify/structure/objects/top_level.rb', line 9

def origin
  @origin
end

Instance Method Details

#as(origin) ⇒ Object



96
97
98
99
100
# File 'lib/jsonapionify/structure/objects/top_level.rb', line 96

def as(origin)
  copy.tap do |obj|
    obj.instance_variable_set :@origin, origin
  end
end

#compile(**opts) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/jsonapionify/structure/objects/top_level.rb', line 80

def compile(**opts)
  compiled        = super(**opts)
  compiled_errors = compiled['errors'] || []
  all_errors      = compiled_errors | errors.as_collection.compile
  if all_errors.present?
    self.class.new(
      errors: all_errors,
      meta:   {
        invalid_object: to_h
      }
    ).compile
  else
    compiled
  end
end