Skip to content

Instantly share code, notes, and snippets.

@coryodaniel
Created July 11, 2016 16:19
Show Gist options
  • Select an option

  • Save coryodaniel/b81b12ed78005b14f4e8ef9a8aef9b67 to your computer and use it in GitHub Desktop.

Select an option

Save coryodaniel/b81b12ed78005b14f4e8ef9a8aef9b67 to your computer and use it in GitHub Desktop.
Break up (apiary) blueprints into smaller manageable git-friendly pieces and compile together.
# * /blueprints
# * /{version_name}
# *
# * manifest.yml
#
# :v1:
# - meta
# - structures/*
# - resources/addresses
# - resources/countries
# - resources/credit_cards
namespace :blueprint do
desc "Compiles blueprints/manifest.yml into doc/"
task compile: :environment do
config = YAML.load_file("blueprints/manifest.yml")
config.each do |version, files|
extension = ".apib"
relative_directory = "blueprints/#{version}"
directory = Rails.root.join(relative_directory)
doc_file = Rails.root.join("doc/#{version}#{extension}")
puts([
"Compiling: #{version}",
"\tFrom: #{directory}",
"\tTo: #{doc_file}"
].join("\n"))
if !File.exists?(directory) || !files.present?
puts("\tSKIPPING #{directory}:\n\tNo manifest files found.")
next
end
resolved_files = files.map do |entry|
fullpath = directory.join(entry)
if entry.index('*')
# Expand globs
Dir.glob(fullpath)
elsif fullpath.to_s !~ /\.#{extension}$/
# Append .apib if missing
[fullpath,extension].join
end
end
resolved_files.flatten!
data = resolved_files.reduce([]) do |acc, file|
acc.push(File.read(file))
end
FileUtils.mkdir('doc') unless File.exist?('doc')
File.open(doc_file, "w+") do |fs|
fs.puts data.join("\n")
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment