Sha256: 48d2ef3d9e90eb078c527385ce188a5414be398642305368b1a94a3f7ead0e85

Contents?: true

Size: 1.44 KB

Versions: 6

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

module Scim
  module Kit
    module V2
      # Represents a ResourceType Schema
      # https://tools.ietf.org/html/rfc7643#section-6
      class ResourceType
        include Templatable
        attr_accessor :id
        attr_accessor :name
        attr_accessor :description
        attr_accessor :endpoint
        attr_accessor :schema
        attr_reader :schema_extensions
        attr_accessor :meta

        def initialize(location:)
          @meta = Meta.new('ResourceType', location)
          @meta.version = @meta.created = @meta.last_modified = nil
          @schema_extensions = []
        end

        def add_schema_extension(schema:, required: false)
          @schema_extensions.push(schema: schema, required: required)
        end

        class << self
          def build(*args)
            item = new(*args)
            yield item
            item
          end

          def from(hash)
            x = new(location: hash[:location])
            x.meta = Meta.from(hash[:meta])
            %i[id name description endpoint schema].each do |key|
              x.public_send("#{key}=", hash[key])
            end
            hash[:schemaExtensions].each do |y|
              x.add_schema_extension(schema: y[:schema], required: y[:required])
            end
            x
          end

          def parse(json)
            from(JSON.parse(json, symbolize_names: true))
          end
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
scim-kit-0.5.1 lib/scim/kit/v2/resource_type.rb
scim-kit-0.5.0 lib/scim/kit/v2/resource_type.rb
scim-kit-0.4.0 lib/scim/kit/v2/resource_type.rb
scim-kit-0.3.2 lib/scim/kit/v2/resource_type.rb
scim-kit-0.3.1 lib/scim/kit/v2/resource_type.rb
scim-kit-0.3.0 lib/scim/kit/v2/resource_type.rb