Class: RailsApiDocs::Config::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/rails-api-docs/config/builder.rb

Overview

Turns the array of route hashes produced by RouteInspector into the full config structure that gets written to config/rails-api-docs.yml.

Output shape:

{
  "general_configurations" => { ... defaults ... },
  "sections" => {
    "<controller_key>" => {
      "name" => "...",
      "description" => "",
      "show" => true,
      "endpoints" => [ { "method" =>, "path" =>, ... }, ... ]
    }
  }
}

Constant Summary collapse

DEFAULT_GENERAL =
{
  "title"           => "API Documentation",
  "base_url"        => "https://api.example.com",
  "primary_color"   => "#CC0000",
  "secondary_color" => "#2E2E2E",
  "accent_color"    => "#D30001",
  "font_family"     => "system-ui, -apple-system, sans-serif",
  "show_curl"       => true,
  "show_examples"   => true
}.freeze
ACTION_VERB_PHRASE =
{
  "index"   => "List",
  "show"    => "Show",
  "new"     => "New",
  "create"  => "Create",
  "edit"    => "Edit",
  "update"  => "Update",
  "destroy" => "Delete"
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(routes:, general: nil, body_inferrer: nil, verbose: false) ⇒ Builder

Returns a new instance of Builder.



45
46
47
48
49
50
# File 'lib/rails-api-docs/config/builder.rb', line 45

def initialize(routes:, general: nil, body_inferrer: nil, verbose: false)
  @routes        = routes
  @general       = general || DEFAULT_GENERAL.dup
  @body_inferrer = body_inferrer
  @verbose       = verbose
end

Instance Method Details

#callObject



52
53
54
55
56
57
# File 'lib/rails-api-docs/config/builder.rb', line 52

def call
  {
    "general_configurations" => @general,
    "sections"               => build_sections
  }
end

#to_yamlObject



59
60
61
# File 'lib/rails-api-docs/config/builder.rb', line 59

def to_yaml
  YAML.dump(call)
end