Sha256: ea832be5b37f0c4f73d30e4b4fe18dab512b6111f022215e9f005495aede99a3

Contents?: true

Size: 1.31 KB

Versions: 94

Compression:

Stored size: 1.31 KB

Contents

class OpenApiConstraint
  OPEN_API_PRODUCTS = Dir.glob("#{Rails.configuration.oas_path}/**/*.yml").map do |dir|
    dir.gsub("#{Rails.configuration.oas_path}/", '').gsub('.yml', '')
  end

  def self.list
    @list ||= OPEN_API_PRODUCTS.sort.reject { |d| d.include? 'common/' }
  end

  def self.products
    { definition: Regexp.new("^(#{list.join('|')})$") }
  end

  def self.errors_available
    all = list.dup.concat(['application'])
    { definition: Regexp.new(all.join('|')) }
  end

  def self.products_with_code_language
    products.merge(Nexmo::Markdown::CodeLanguage.route_constraint)
  end

  def self.find_all_versions(name)
    # Remove the .v2 etc if needed
    name = name.gsub(/(\.v\d+)/, '')

    matches = list.select do |s|
      s.starts_with?(name) && s.exclude?("#{name}/")
    end

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

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

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

  def self.match?(definition, code_language = nil)
    if code_language.nil?
      products_with_code_language[:definition].match?(definition)
    else
      products_with_code_language[:definition].match?(definition) &&
        products_with_code_language[:code_language].match?(code_language)
    end
  end
end

Version data entries

94 entries across 94 versions & 1 rubygems

Version Path
station-0.5.16 lib/nexmo_developer/app/constraints/open_api_constraint.rb
station-0.5.15 lib/nexmo_developer/app/constraints/open_api_constraint.rb
station-0.5.14 lib/nexmo_developer/app/constraints/open_api_constraint.rb
station-0.5.13 lib/nexmo_developer/app/constraints/open_api_constraint.rb
station-0.5.12 lib/nexmo_developer/app/constraints/open_api_constraint.rb
station-0.5.11 lib/nexmo_developer/app/constraints/open_api_constraint.rb
station-0.5.10 lib/nexmo_developer/app/constraints/open_api_constraint.rb
station-0.5.9 lib/nexmo_developer/app/constraints/open_api_constraint.rb
station-0.5.8 lib/nexmo_developer/app/constraints/open_api_constraint.rb
station-0.5.7 lib/nexmo_developer/app/constraints/open_api_constraint.rb
station-0.5.6 lib/nexmo_developer/app/constraints/open_api_constraint.rb
station-0.5.5 lib/nexmo_developer/app/constraints/open_api_constraint.rb
station-0.5.4 lib/nexmo_developer/app/constraints/open_api_constraint.rb
station-0.5.3 lib/nexmo_developer/app/constraints/open_api_constraint.rb
station-0.5.2 lib/nexmo_developer/app/constraints/open_api_constraint.rb
station-0.5.1 lib/nexmo_developer/app/constraints/open_api_constraint.rb
station-0.5.0 lib/nexmo_developer/app/constraints/open_api_constraint.rb
station-0.4.9 lib/nexmo_developer/app/constraints/open_api_constraint.rb
station-0.4.8 lib/nexmo_developer/app/constraints/open_api_constraint.rb
station-0.4.7 lib/nexmo_developer/app/constraints/open_api_constraint.rb