module Apiary::Helpers

Public Instance Methods

api_description_source(path) click to toggle source
# File lib/apiary/helpers.rb, line 15
def api_description_source(path)
  source_path = api_description_source_path(path)
  source = nil
  File.open(source_path, 'r:bom|utf-8') { |file| source = file.read }
  source
end
api_description_source_path(path) click to toggle source
# File lib/apiary/helpers.rb, line 7
def api_description_source_path(path)
  raise "Invalid path #{path}" unless File.exist? path
  return path if File.file? path
  source_path = choose_one(path)
  return source_path unless source_path.nil?
  raise 'No API Description Document found'
end
convert_from_json(add) click to toggle source
# File lib/apiary/helpers.rb, line 22
def convert_from_json(add)
  JSON.parse(add).to_yaml
rescue JSON::ParserError => e
  abort "Unable to convert input document to yaml: #{e.message.lines.first}"
end

Protected Instance Methods

api_blueprint(path) click to toggle source
# File lib/apiary/helpers.rb, line 41
def api_blueprint(path)
  source_path = File.join(path, 'apiary.apib')
  return source_path if File.exist? source_path
  nil
end
choose_one(path) click to toggle source
# File lib/apiary/helpers.rb, line 30
def choose_one(path)
  apib_path = api_blueprint(path)
  swagger_path = swagger(path)

  if apib_path && swagger_path
    warn 'WARNING: Both apiary.apib and swagger.yaml are present. The apiary.apib file will be used. To override this selection specify path to desired file'
  end

  apib_path || swagger_path
end
swagger(path) click to toggle source
# File lib/apiary/helpers.rb, line 47
def swagger(path)
  source_path = File.join(path, 'swagger.yaml')
  return source_path if File.exist? source_path
  nil
end