Class: Verquest::Versions

Inherits:
Object
  • Object
show all
Defined in:
lib/verquest/versions.rb

Overview

Container for managing multiple API versions

The Versions class stores and provides access to all available versions of an API request schema. It handles adding new versions and resolving version identifiers to specific Version objects based on the configured version resolution strategy.

Examples:

Adding and resolving versions

versions = Verquest::Versions.new

# Add versions
versions.add(Verquest::Version.new(name: "2022-01"))
versions.add(Verquest::Version.new(name: "2023-01"))

# Resolve a version
version = versions.resolve("2022-06") # Returns "2022-01" version based on resolver

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeVersions

Initialize a new Versions container



30
31
32
33
# File 'lib/verquest/versions.rb', line 30

def initialize
  @versions = {}
  @schema_options = {}
end

Instance Attribute Details

#descriptionString

Returns Default description for versions that don’t specify one.

Returns:

  • (String)

    Default description for versions that don’t specify one



25
26
27
# File 'lib/verquest/versions.rb', line 25

def description
  @description
end

#schema_optionsHash

Returns Default schema options for versions that don’t specify any.

Returns:

  • (Hash)

    Default schema options for versions that don’t specify any



25
# File 'lib/verquest/versions.rb', line 25

attr_accessor :description, :schema_options

#versionsObject (readonly, private)

Returns the value of attribute versions.



63
64
65
# File 'lib/verquest/versions.rb', line 63

def versions
  @versions
end

Instance Method Details

#add(version) ⇒ Verquest::Version

Add a version to the container

Parameters:

Returns:

Raises:

  • (ArgumentError)

    If the provided object is not a Version instance



40
41
42
43
44
# File 'lib/verquest/versions.rb', line 40

def add(version)
  raise ArgumentError, "Expected a Verquest::Version instance" unless version.is_a?(Verquest::Version)

  versions[version.name] = version
end

#resolve(version_name) ⇒ Verquest::Version

Resolve a version identifier to a specific Version object

Uses the configured version resolver to determine which version to use based on the requested version identifier.

Parameters:

  • version_name (String)

    The version identifier to resolve

Returns:



53
54
55
56
57
# File 'lib/verquest/versions.rb', line 53

def resolve(version_name)
  resolved_version_name = Verquest.configuration.version_resolver.call(version_name, versions.keys.sort)

  versions[resolved_version_name] || raise(Verquest::VersionNotFoundError, "Version '#{version_name}' not found")
end