Sha256: fa191f39ea786a454325b89651703f9e00499f8eb52dc60c9f0ec9f05f5b9957

Contents?: true

Size: 846 Bytes

Versions: 10

Compression:

Stored size: 846 Bytes

Contents

# frozen_string_literal: true

require 'json'

module Workato
  module Connector
    module Sdk
      class WorkatoSchemas
        include Singleton

        class << self
          def from_json(path = DEFAULT_SCHEMAS_PATH)
            load_data(JSON.parse(File.read(path)))
          end

          delegate :find,
                   :load_data,
                   to: :instance
        end

        def load_data(data)
          @schemas_by_id ||= {}.with_indifferent_access
          @schemas_by_id.merge!(data.stringify_keys)
        end

        def find(id)
          unless @schemas_by_id
            raise 'Workato Schemas are not initialized. ' \
                  'Init data by calling WorkatoSchemas.from_json or WorkatoSchemas.load_data'
          end

          @schemas_by_id.fetch(id.to_s)
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
workato-connector-sdk-1.0.1 lib/workato/connector/sdk/workato_schemas.rb
workato-connector-sdk-1.0.0 lib/workato/connector/sdk/workato_schemas.rb
workato-connector-sdk-0.5.0 lib/workato/connector/sdk/workato_schemas.rb
workato-connector-sdk-0.4.1 lib/workato/connector/sdk/workato_schemas.rb
workato-connector-sdk-0.4.0 lib/workato/connector/sdk/workato_schemas.rb
workato-connector-sdk-0.3.0 lib/workato/connector/sdk/workato_schemas.rb
workato-connector-sdk-0.2.0 lib/workato/connector/sdk/workato_schemas.rb
workato-connector-sdk-0.1.2 lib/workato/connector/sdk/workato_schemas.rb
workato-connector-sdk-0.1.1 lib/workato/connector/sdk/workato_schemas.rb
workato-connector-sdk-0.1.0 lib/workato/connector/sdk/workato_schemas.rb