summaryrefslogtreecommitdiff
path: root/lib/api/helpers/version.rb
blob: 7f53094e90c3f1992eef1bbb4e489cd20daa4b6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# frozen_string_literal: true

module API
  module Helpers
    class Version
      include Helpers::RelatedResourcesHelpers

      def initialize(version)
        @version = version.to_s

        unless API.versions.include?(version)
          raise ArgumentError, 'Unknown API version!'
        end
      end

      def root_path
        File.join('/', API.prefix.to_s, @version)
      end

      def root_url
        @root_url ||= expose_url(root_path)
      end

      def to_s
        @version
      end
    end
  end
end