Class: RailsApiDocs::Generators::InitGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/rails-api-docs/init/init_generator.rb

Overview

The full implementation lives here. ‘UpdateGenerator` is a thin alias subclass that just overrides the namespace — see update_generator.rb. Both invocations run identical code; the distinction is semantic:

rails g rails-api-docs:init    # scaffold the YAML the first time
rails g rails-api-docs:update  # re-run to absorb new routes

The generator self-detects whether the YAML already exists and either creates it fresh (init flow) or appends only new routes (update flow). Existing entries are never modified — safe to re-run any time.

Direct Known Subclasses

UpdateGenerator

Instance Method Summary collapse

Instance Method Details

#create_or_update_config_fileObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/generators/rails-api-docs/init/init_generator.rb', line 55

def create_or_update_config_file
  routes    = Inspectors::RouteInspector.new(
                route_set: RailsApiDocs.configuration.route_source,
                config:    scoped_config
              ).call
  routes    = filter_json_only(routes) if api_only?

  inferrer  = Inspectors::BodyInferrer.new(root: destination_root, verbose: verbose_yaml?)
  generated = Config::Builder.new(routes: routes, body_inferrer: inferrer, verbose: verbose_yaml?).call

  if File.exist?(absolute_path)
    append_into_existing(generated)
  else
    create_fresh(generated)
  end
end