Module: Apiary::Helpers

Included in:
Command::Preview, Command::Publish, Command::Styleguide
Defined in:
lib/apiary/helpers.rb

Defined Under Namespace

Modules: JavascriptHelper

Instance Method Summary collapse

Instance Method Details

#api_description_source(path) ⇒ Object



15
16
17
18
19
20
# 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) ⇒ Object



7
8
9
10
11
12
13
# 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) ⇒ Object



22
23
24
25
26
# 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