Class: Scim::Kit::V2::Resource

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations, Templatable, Attributable
Defined in:
lib/scim/kit/v2/resource.rb

Overview

Represents a SCIM Resource

Direct Known Subclasses

Error

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Templatable

#as_json, #render, #to_h, #to_json

Methods included from Attributable

#assign_attributes, #define_attributes_for, #dynamic_attributes

Constructor Details

#initialize(schemas:, location: nil, attributes: {}) {|_self| ... } ⇒ Resource

Returns a new instance of Resource.

Yields:

  • (_self)

Yield Parameters:



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/scim/kit/v2/resource.rb', line 18

def initialize(schemas:, location: nil, attributes: {})
  @meta = Meta.new(schemas[0]&.name, location)
  @meta.disable_timestamps
  @schemas = schemas
  @raw_attributes = attributes
  schemas.each { |x| define_attributes_for(self, x.attributes) }
  attribute(AttributeType.new(name: :id), self)
  attribute(AttributeType.new(name: :external_id), self)
  assign_attributes(attributes)
  yield self if block_given?
end

Instance Attribute Details

#metaObject (readonly)

Returns the value of attribute meta.



12
13
14
# File 'lib/scim/kit/v2/resource.rb', line 12

def meta
  @meta
end

#raw_attributesObject (readonly)

Returns the value of attribute raw_attributes.



14
15
16
# File 'lib/scim/kit/v2/resource.rb', line 14

def raw_attributes
  @raw_attributes
end

#schemasObject (readonly)

Returns the value of attribute schemas.



13
14
15
# File 'lib/scim/kit/v2/resource.rb', line 13

def schemas
  @schemas
end

Instance Method Details

#mode?(type) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
33
34
35
36
37
# File 'lib/scim/kit/v2/resource.rb', line 30

def mode?(type)
  case type.to_sym
  when :server
    meta&.location
  else
    meta&.location.nil?
  end
end

#template_nameObject



39
40
41
# File 'lib/scim/kit/v2/resource.rb', line 39

def template_name
  'resource.json.jbuilder'
end