Class: Nexmo::OAS::Renderer::Presenters::Versions

Inherits:
Object
  • Object
show all
Defined in:
lib/nexmo/oas/renderer/presenters/versions.rb

Instance Method Summary collapse

Constructor Details

#initialize(definition_name) ⇒ Versions

Returns a new instance of Versions.



8
9
10
# File 'lib/nexmo/oas/renderer/presenters/versions.rb', line 8

def initialize(definition_name)
  @definition_name = definition_name
end

Instance Method Details

#available_versionsObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/nexmo/oas/renderer/presenters/versions.rb', line 23

def available_versions
  @available_versions ||= begin
                            matches = definitions.select do |definition|
                              definition.match(/^#{base_name}(\.v\d+)?$/) && !definition.include?("#{base_name}/")
                            end

                            matches = matches.map do |definition|
                              m = /\.v(\d+)/.match(definition)
                              next { 'version' => '1', 'name' => definition } unless m

                              { 'version' => m[1], 'name' => definition }
                            end

                            matches.sort_by { |v| v['version'] }
                          end
end

#base_nameObject



12
13
14
# File 'lib/nexmo/oas/renderer/presenters/versions.rb', line 12

def base_name
  @base_name ||= @definition_name.gsub(/\.v\d+/, '')
end

#current_versionObject



16
17
18
19
20
21
# File 'lib/nexmo/oas/renderer/presenters/versions.rb', line 16

def current_version
  @current_version ||= begin
                         m = /\.v(\d+)/.match(@definition_name)
                         m.nil? ? '1' : m[1]
                       end
end

#definitionsObject



40
41
42
43
44
45
46
# File 'lib/nexmo/oas/renderer/presenters/versions.rb', line 40

def definitions
  @definitions ||= begin
                     Dir.glob("#{API.oas_path}/**/*.yml").map do |file|
                       file.sub("#{API.oas_path}/", '').chomp('.yml')
                     end
                   end
end