Sha256: a88dbe7d76dea1a70c7c352dbdfe8af0c494a3f612e51ab11b03140df2c084c6

Contents?: true

Size: 1.18 KB

Versions: 7

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true
# typed: true

module WorkOS
  # The Directory class provides a lightweight wrapper around
  # a WorkOS Directory resource. This class is not meant to be instantiated
  # in user space, and is instantiated internally but exposed.
  class Directory
    extend T::Sig

    attr_accessor :id, :domain, :name, :type, :state

    sig { params(json: String).void }
    def initialize(json)
      raw = parse_json(json)

      @id = T.let(raw.id, String)
      @name = T.let(raw.name, String)
      @domain = T.let(raw.domain, String)
      @type = T.let(raw.type, String)
      @state = T.let(raw.state, String)
    end

    def to_json(*)
      {
        id: id,
        name: name,
        domain: domain,
        type: type,
        state: state,
      }
    end

    private

    sig do
      params(
        json_string: String,
      ).returns(WorkOS::Types::DirectoryStruct)
    end
    def parse_json(json_string)
      hash = JSON.parse(json_string, symbolize_names: true)

      WorkOS::Types::DirectoryStruct.new(
        id: hash[:id],
        name: hash[:name],
        domain: hash[:domain],
        type: hash[:type],
        state: hash[:state],
      )
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
workos-1.2.1 lib/workos/directory.rb
workos-1.2.0 lib/workos/directory.rb
workos-1.1.0 lib/workos/directory.rb
workos-1.0.0 lib/workos/directory.rb
workos-0.11.2 lib/workos/directory.rb
workos-0.11.1 lib/workos/directory.rb
workos-0.11.0 lib/workos/directory.rb