Class: Verquest::Versions
- Inherits:
-
Object
- Object
- Verquest::Versions
- 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.
Instance Attribute Summary collapse
-
#description ⇒ String
Default description for versions that don’t specify one.
-
#schema_options ⇒ Hash
Default schema options for versions that don’t specify any.
-
#versions ⇒ Object
readonly
private
Returns the value of attribute versions.
Instance Method Summary collapse
-
#add(version) ⇒ Verquest::Version
Add a version to the container.
-
#initialize ⇒ Versions
constructor
Initialize a new Versions container.
-
#resolve(version_name) ⇒ Verquest::Version
Resolve a version identifier to a specific Version object.
Constructor Details
#initialize ⇒ Versions
Initialize a new Versions container
30 31 32 33 |
# File 'lib/verquest/versions.rb', line 30 def initialize @versions = {} = {} end |
Instance Attribute Details
#description ⇒ String
Returns Default description for versions that don’t specify one.
25 26 27 |
# File 'lib/verquest/versions.rb', line 25 def description @description end |
#schema_options ⇒ Hash
Returns Default schema options for versions that don’t specify any.
25 |
# File 'lib/verquest/versions.rb', line 25 attr_accessor :description, :schema_options |
#versions ⇒ Object (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
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.
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 |