2015-08-26 19:58:49 -04:00
|
|
|
services_template = <<-ERB
|
|
|
|
# Services
|
|
|
|
|
|
|
|
<% services.each do |service| %>
|
|
|
|
## <%= service[:title] %>
|
|
|
|
|
|
|
|
|
|
|
|
<% unless service[:description].blank? %>
|
|
|
|
<%= service[:description] %>
|
|
|
|
<% end %>
|
|
|
|
|
|
|
|
|
|
|
|
### Create/Edit <%= service[:title] %> service
|
|
|
|
|
|
|
|
Set <%= service[:title] %> service for a project.
|
|
|
|
<% unless service[:help].blank? %>
|
|
|
|
|
|
|
|
> <%= service[:help].gsub("\n", ' ') %>
|
|
|
|
|
|
|
|
<% end %>
|
|
|
|
|
|
|
|
```
|
|
|
|
PUT /projects/:id/services/<%= service[:dashed_name] %>
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
|
|
|
|
<% service[:params].each do |param| %>
|
|
|
|
- `<%= param[:name] %>` <%= param[:required] ? "(**required**)" : "(optional)" %><%= [" -", param[:description]].join(" ").gsub("\n", '') unless param[:description].blank? %>
|
|
|
|
|
|
|
|
<% end %>
|
|
|
|
|
|
|
|
### Delete <%= service[:title] %> service
|
|
|
|
|
|
|
|
Delete <%= service[:title] %> service for a project.
|
|
|
|
|
|
|
|
```
|
|
|
|
DELETE /projects/:id/services/<%= service[:dashed_name] %>
|
|
|
|
|
|
|
|
```
|
|
|
|
|
2015-09-03 09:38:54 -04:00
|
|
|
### Get <%= service[:title] %> service settings
|
|
|
|
|
|
|
|
Get <%= service[:title] %> service settings for a project.
|
|
|
|
|
|
|
|
```
|
|
|
|
GET /projects/:id/services/<%= service[:dashed_name] %>
|
|
|
|
|
|
|
|
```
|
|
|
|
|
2015-08-26 19:58:49 -04:00
|
|
|
<% end %>
|
|
|
|
ERB
|
|
|
|
|
|
|
|
namespace :services do
|
2015-09-03 16:49:13 -04:00
|
|
|
task doc: :environment do
|
2015-08-26 19:58:49 -04:00
|
|
|
services = Service.available_services_names.map do |s|
|
|
|
|
service_start = Time.now
|
|
|
|
klass = "#{s}_service".classify.constantize
|
2015-09-03 16:49:13 -04:00
|
|
|
|
2015-08-26 19:58:49 -04:00
|
|
|
service = klass.new
|
|
|
|
|
|
|
|
service_hash = {}
|
|
|
|
|
|
|
|
service_hash[:title] = service.title
|
|
|
|
service_hash[:dashed_name] = s.dasherize
|
|
|
|
service_hash[:description] = service.description
|
|
|
|
service_hash[:help] = service.help
|
|
|
|
service_hash[:params] = service.fields.map do |p|
|
|
|
|
param_hash = {}
|
|
|
|
|
|
|
|
param_hash[:name] = p[:name]
|
|
|
|
param_hash[:description] = p[:placeholder] || p[:title]
|
2015-09-03 16:49:13 -04:00
|
|
|
param_hash[:required] = klass.validators_on(p[:name].to_sym).any? do |v|
|
2015-08-26 19:58:49 -04:00
|
|
|
v.class == ActiveRecord::Validations::PresenceValidator
|
|
|
|
end
|
|
|
|
|
|
|
|
param_hash
|
2017-02-22 13:18:40 -05:00
|
|
|
end
|
|
|
|
service_hash[:params].sort_by! { |p| p[:required] ? 0 : 1 }
|
2015-08-26 19:58:49 -04:00
|
|
|
|
2017-02-22 13:18:40 -05:00
|
|
|
puts "Collected data for: #{service.title}, #{Time.now - service_start}"
|
2015-08-26 19:58:49 -04:00
|
|
|
service_hash
|
|
|
|
end
|
|
|
|
|
|
|
|
doc_start = Time.now
|
|
|
|
doc_path = File.join(Rails.root, 'doc', 'api', 'services.md')
|
|
|
|
|
2017-02-22 13:18:40 -05:00
|
|
|
result = ERB.new(services_template, 0, '>')
|
2015-08-26 19:58:49 -04:00
|
|
|
.result(OpenStruct.new(services: services).instance_eval { binding })
|
|
|
|
|
|
|
|
File.open(doc_path, 'w') do |f|
|
|
|
|
f.write result
|
|
|
|
end
|
|
|
|
|
2017-02-22 13:18:40 -05:00
|
|
|
puts "write a new service.md to: #{doc_path}, #{Time.now - doc_start}"
|
2015-08-26 19:58:49 -04:00
|
|
|
end
|
|
|
|
end
|