Class: DocumentationConstraint

Inherits:
Object
  • Object
show all
Defined in:
lib/nexmo_developer/app/constraints/documentation_constraint.rb

Class Method Summary collapse

Class Method Details

.configObject



20
21
22
23
24
# File 'lib/nexmo_developer/app/constraints/documentation_constraint.rb', line 20

def self.config
  @config ||= YAML.safe_load(
    File.read("#{Rails.configuration.docs_base_path}/config/products.yml")
  )
end

.documentationObject



2
3
4
# File 'lib/nexmo_developer/app/constraints/documentation_constraint.rb', line 2

def self.documentation
  Nexmo::Markdown::CodeLanguage.route_constraint.merge(product_with_parent)
end

.product_with_parentObject



10
11
12
# File 'lib/nexmo_developer/app/constraints/documentation_constraint.rb', line 10

def self.product_with_parent
  { product: Regexp.new(product_with_parent_list.compact.reverse.join('|')) }
end

.product_with_parent_listObject

Raises:

  • (ArgumentError)


14
15
16
17
18
# File 'lib/nexmo_developer/app/constraints/documentation_constraint.rb', line 14

def self.product_with_parent_list
  raise ArgumentError, "The 'product' key in config/products.yml must be a list with at least one entry." if config.fetch('products', []).size.zero?

  @product_with_parent_list ||= config.fetch('products', []).map { |product| product['path'] }
end

.products_for_routesObject



6
7
8
# File 'lib/nexmo_developer/app/constraints/documentation_constraint.rb', line 6

def self.products_for_routes
  product_with_parent_list
end