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, #attribute_for, #define_attributes_for, #dynamic_attributes, #each, #read_attribute, #write_attribute

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)



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

def meta
  @meta
end

#raw_attributesObject (readonly)



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

def raw_attributes
  @raw_attributes
end

#schemasObject (readonly)



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

def schemas
  @schemas
end

Instance Method Details

#mode?(type) ⇒ Boolean

Returns the current mode.

Parameters:

  • type (Symbol)

    The mode ‘:server` or `:client`.

Returns:

  • (Boolean)

    Returns true if the resource matches the # type of mode



34
35
36
37
38
39
40
41
# File 'lib/scim/kit/v2/resource.rb', line 34

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

#template_nameString

Returns the name of the jbuilder template file.

Returns:

  • (String)

    the name of the jbuilder template.



45
46
47
# File 'lib/scim/kit/v2/resource.rb', line 45

def template_name
  'resource.json.jbuilder'
end