Method: Scimitar::Resources::Base#as_json

Defined in:
app/models/scimitar/resources/base.rb

#as_json(options = {}) ⇒ Object

Renders *in full* as JSON; typically used for write-based operations…

record = self.storage_class().new
record.from_scim!(scim_hash: scim_resource.as_json())
self.save!(record)

…so all fields, even those marked “returned: false”, are included. Use Scimitar::Resources::Mixin::to_scim to obtain a SCIM object with non-returnable fields omitted, rendering that as JSON via #to_json.



181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'app/models/scimitar/resources/base.rb', line 181

def as_json(options = {})
  self.meta = Meta.new unless self.meta && self.meta.is_a?(Meta)
  self.meta.resourceType = self.class.resource_type_id

  original_hash = super(options).except('errors')
  original_hash.merge!('schemas' => self.class.schemas.map(&:id))

  self.class.extended_schemas.each do |extension_schema|
    extension_attributes = extension_schema.scim_attributes.map(&:name)
    original_hash.merge!(extension_schema.id => original_hash.extract!(*extension_attributes))
  end

  original_hash
end