johnhamelink
3/23/2015 - 4:56 PM

Rakefile

# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path('../config/application', __FILE__)

Rails.application.load_tasks

desc 'API Routes'
task :routes do
  max_path, max_description = 0, 0
  apis = []

  T5::V1::Base.routes.each do |api|
    # rubocop:disable Style/IfUnlessModifier
    if api.route_path.length > max_path
      max_path = api.route_path.length
    end

    if api.route_description && api.route_description.length > max_description
      max_description = api.route_description.length
    end

    apis << [
      api.route_method,
      api.route_path,
      api.route_description
    ]
    # rubocop:enable Style/IfUnlessModifier
  end

  apis.uniq!

  apis.each do |api|
    format = "%-4s %-#{max_path}s %-#{max_description}s\r\n"
    printf(format, api[0], api[1], api[2])
  end

end

desc 'Deploy to production'
task :deploy do
  exec("cd #{File.dirname(__FILE__)}/../deploy && ansible-playbook deploy_api.yml -i hosts && cd -")
end