Class: ScimEngine::Schema::Base

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
app/models/scim_engine/schema/base.rb

Overview

The base class that each schema class must inherit from. These classes represent the schema of a SCIM resource or a complex type that could be used in a resource.

Direct Known Subclasses

Email, Group, Name, Reference, User

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Returns a new instance of Base.


9
10
11
12
# File 'app/models/scim_engine/schema/base.rb', line 9

def initialize(options = {})
  super
  @meta = Meta.new(resourceType: "Schema")
end

Instance Attribute Details

#descriptionObject

Returns the value of attribute description


7
8
9
# File 'app/models/scim_engine/schema/base.rb', line 7

def description
  @description
end

#idObject

Returns the value of attribute id


7
8
9
# File 'app/models/scim_engine/schema/base.rb', line 7

def id
  @id
end

#metaObject

Returns the value of attribute meta


7
8
9
# File 'app/models/scim_engine/schema/base.rb', line 7

def meta
  @meta
end

#nameObject

Returns the value of attribute name


7
8
9
# File 'app/models/scim_engine/schema/base.rb', line 7

def name
  @name
end

#scim_attributesObject

Returns the value of attribute scim_attributes


7
8
9
# File 'app/models/scim_engine/schema/base.rb', line 7

def scim_attributes
  @scim_attributes
end

Class Method Details

.cloned_scim_attributesObject


29
30
31
# File 'app/models/scim_engine/schema/base.rb', line 29

def self.cloned_scim_attributes
  scim_attributes.map { |scim_attribute| scim_attribute.clone }
end

.valid?(resource) ⇒ Boolean

Validates the resource against specific validations of each attribute,for example if the type of the attribute matches the one defined in the schema.

Parameters:

  • resource (Object)

    a resource object that uses this schema

Returns:

  • (Boolean)

23
24
25
26
27
# File 'app/models/scim_engine/schema/base.rb', line 23

def self.valid?(resource)
  cloned_scim_attributes.each do |scim_attribute|
    resource.add_errors_from_hash(scim_attribute.errors.to_hash) unless scim_attribute.valid?(resource.send(scim_attribute.name))
  end
end

Instance Method Details

#as_json(options = {}) ⇒ Object

Converts the schema to its json representation that will be returned by /SCHEMAS end-point of a SCIM service provider.


15
16
17
18
19
# File 'app/models/scim_engine/schema/base.rb', line 15

def as_json(options = {})
  @meta.location = ScimEngine::Engine.routes.url_helpers.scim_schemas_path(name: id)
  original = super
  original.merge('attributes' => original.delete('scim_attributes'))
end