Class: DiscoveryV1::Validation::LoadSchemas Private

Inherits:
Object
  • Object
show all
Defined in:
lib/discovery_v1/validation/load_schemas.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Load the Google Discovery V1 API description for the Discovery V1 API

Examples:

logger = Logger.new(STDOUT, :level => Logger::ERROR)
schemas = DiscoveryV1::Validation::LoadSchemas.new(logger:).call

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rest_description:, logger: Logger.new(nil)) ⇒ LoadSchemas

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Loads schemas for the Discovery V1 API object from the Google Discovery V1 API

By default, a nil logger is used. This means that nothing is logged.

The schemas are only loaded once and cached.

Examples:

schema_loader = DiscoveryV1::Validation::LoadSchemas.new

Parameters:



30
31
32
33
# File 'lib/discovery_v1/validation/load_schemas.rb', line 30

def initialize(rest_description:, logger: Logger.new(nil))
  @rest_description = rest_description
  @logger = logger
end

Class Attribute Details

.load_schemas_mutexThread::Mutex (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

A mutex used to synchronize access to the schemas so they are only loaded once

Returns:

  • (Thread::Mutex)


99
100
101
# File 'lib/discovery_v1/validation/load_schemas.rb', line 99

def load_schemas_mutex
  @load_schemas_mutex
end

Instance Attribute Details

#loggerLogger (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The logger to use internally for logging errors

Examples:

logger = Logger.new(STDOUT, :level => Logger::INFO)
schema_loader = DiscoveryV1::Validation::LoadSchemas.new(logger)
schema_loader.logger == logger # => true

Returns:

  • (Logger)


55
56
57
# File 'lib/discovery_v1/validation/load_schemas.rb', line 55

def logger
  @logger
end

#rest_descriptionGoogle::Apis::DiscoveryV1::RestDescription (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The Google Discovery V1 API description to load schemas from

Examples:

rest_description = DiscoveryV1.discovery_service.get_rest_description('sheets', 'v4')
loader = DiscoveryV1::Validation::LoadSchemas.new(rest_description:)
loader.rest_description == rest_description # => true

Returns:



44
45
46
# File 'lib/discovery_v1/validation/load_schemas.rb', line 44

def rest_description
  @rest_description
end

Class Method Details

.clear_schemas_cache

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Clear the memoization cache (intended for testing)



134
135
136
# File 'lib/discovery_v1/validation/load_schemas.rb', line 134

def clear_schemas_cache
  @schemas_cache = {}
end

.memoize_schemas(rest_description:, schemas:) ⇒ Hash<String, Object>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Memoize the schemas for the given rest_description returning the given schemas

Parameters:

Returns:

  • (Hash<String, Object>)

    the given schemas



124
125
126
# File 'lib/discovery_v1/validation/load_schemas.rb', line 124

def memoize_schemas(rest_description:, schemas:)
  @schemas_cache[rest_description.canonical_name] = schemas
end

.schemas(rest_description:) ⇒ Hash<String, Object>?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The memoized schemas for the given rest_description or nil

Parameters:

Returns:

  • (Hash<String, Object>, nil)

    a hash of schemas keyed by schema name



110
111
112
# File 'lib/discovery_v1/validation/load_schemas.rb', line 110

def schemas(rest_description:)
  @schemas_cache[rest_description.canonical_name]
end

Instance Method Details

#callHash<String, Object>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

A hash of schemas keyed by schema name loaded from the Google Discovery V1 API

Examples:

DiscoveryV1.api_object_schemas #=> { 'PersonSchema' => { 'type' => 'object', ... } ... }

Returns:

  • (Hash<String, Object>)

    a hash of schemas keyed by schema name



64
65
66
67
68
69
# File 'lib/discovery_v1/validation/load_schemas.rb', line 64

def call
  self.class.load_schemas_mutex.synchronize do
    self.class.schemas(rest_description:) ||
      self.class.memoize_schemas(rest_description:, schemas: load_api_schemas)
  end
end