class Fictium::ApiBlueprintExporter

Public Instance Methods

export(document) click to toggle source
# File lib/fictium/exporters/api_blueprint_exporter.rb, line 11
def export(document)
  result = process_file(document).presence || ''
  FileUtils.mkdir_p(File.dirname(export_file))
  File.write(export_file, result)
end

Private Instance Methods

build_header(document) click to toggle source
# File lib/fictium/exporters/api_blueprint_exporter.rb, line 29
def build_header(document)
  header_formatter.format(document)
end
build_resources(document) click to toggle source
# File lib/fictium/exporters/api_blueprint_exporter.rb, line 33
def build_resources(document)
  mapped_resources = document.resources.map do |resource|
    resource_formatter.format(resource)
  end
  mapped_resources = clean_items(mapped_resources)
  mapped_resources.present? ? "# Group #{resources_group_name} \n\n#{mapped_resources}" : ''
end
clean_items(items) click to toggle source
# File lib/fictium/exporters/api_blueprint_exporter.rb, line 61
def clean_items(items)
  items.select(&:present?).join("\n\n")
end
export_file() click to toggle source
# File lib/fictium/exporters/api_blueprint_exporter.rb, line 24
def export_file
  @export_file ||=
    File.join(Fictium.configuration.export_path, 'api_blueprint', 'api.apib')
end
header_formatter() click to toggle source
# File lib/fictium/exporters/api_blueprint_exporter.rb, line 45
def header_formatter
  HeaderFormatter.new
end
process_file(document) click to toggle source
# File lib/fictium/exporters/api_blueprint_exporter.rb, line 19
def process_file(document)
  list = [build_header(document), build_footer(document), build_resources(document)]
  clean_items(list)
end
resource_formatter() click to toggle source
# File lib/fictium/exporters/api_blueprint_exporter.rb, line 49
def resource_formatter
  @resource_formatter ||= ResourceFormatter.new
end
resources_group_name() click to toggle source
# File lib/fictium/exporters/api_blueprint_exporter.rb, line 57
def resources_group_name
  Fictium.configuration.api_blueprint.resources_group_name
end