Class: OpenApiConstraint
- Inherits:
-
Object
- Object
- OpenApiConstraint
- Defined in:
- lib/nexmo_developer/app/constraints/open_api_constraint.rb
Constant Summary collapse
- OPEN_API_PRODUCTS =
Dir.glob("#{Rails.configuration.oas_path}/**/*.yml").map do |dir| dir.gsub("#{Rails.configuration.oas_path}/", '').gsub('.yml', '') end
Class Method Summary collapse
- .errors_available ⇒ Object
- .find_all_versions(name) ⇒ Object
- .list ⇒ Object
- .match?(definition, code_language = nil) ⇒ Boolean
- .products ⇒ Object
- .products_with_code_language ⇒ Object
Class Method Details
.errors_available ⇒ Object
14 15 16 17 |
# File 'lib/nexmo_developer/app/constraints/open_api_constraint.rb', line 14 def self.errors_available all = list.dup.concat(['application']) { definition: Regexp.new(all.join('|')) } end |
.find_all_versions(name) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/nexmo_developer/app/constraints/open_api_constraint.rb', line 23 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 |
.list ⇒ Object
6 7 8 |
# File 'lib/nexmo_developer/app/constraints/open_api_constraint.rb', line 6 def self.list @list ||= OPEN_API_PRODUCTS.sort.reject { |d| d.include? 'common/' } end |
.match?(definition, code_language = nil) ⇒ Boolean
41 42 43 44 45 46 47 48 |
# File 'lib/nexmo_developer/app/constraints/open_api_constraint.rb', line 41 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 |
.products ⇒ Object
10 11 12 |
# File 'lib/nexmo_developer/app/constraints/open_api_constraint.rb', line 10 def self.products { definition: Regexp.new("^(#{list.join('|')})$") } end |
.products_with_code_language ⇒ Object
19 20 21 |
# File 'lib/nexmo_developer/app/constraints/open_api_constraint.rb', line 19 def self.products_with_code_language products.merge(Nexmo::Markdown::CodeLanguage.route_constraint) end |