Class: RailsApiDocs::Config::Appender

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

Overview

Append-only merge between an existing parsed config and a freshly generated one.

Rules:

- Endpoint identity = "#{method} #{path}".
- Existing endpoints win on every field (user edits are sacred).
- New endpoints (not in existing) are appended to their section's
  `endpoints` array in the order returned by RouteInspector.
- Brand-new sections are appended at the end of `sections`.
- `general_configurations`: existing keys win; only missing keys
  are filled in from the generated defaults — so a new gem version
  introducing a new option doesn't force a manual edit.

Instance Method Summary collapse

Constructor Details

#initialize(existing:, generated:) ⇒ Appender

Returns a new instance of Appender.



18
19
20
21
# File 'lib/rails-api-docs/config/appender.rb', line 18

def initialize(existing:, generated:)
  @existing  = existing  || {}
  @generated = generated || {}
end

Instance Method Details

#callObject



23
24
25
26
27
28
# File 'lib/rails-api-docs/config/appender.rb', line 23

def call
  {
    "general_configurations" => merge_general,
    "sections"               => merge_sections
  }
end

#changes?Boolean

Returns:

  • (Boolean)


38
39
40
41
# File 'lib/rails-api-docs/config/appender.rb', line 38

def changes?
  d = diff
  !d[:new_sections].empty? || !d[:new_endpoints_by_section].empty?
end

#diffObject

{ new_sections: [keys…], new_endpoints_by_section: { key => [endpoints…] } }



31
32
33
34
35
36
# File 'lib/rails-api-docs/config/appender.rb', line 31

def diff
  {
    new_sections: new_section_keys,
    new_endpoints_by_section: new_endpoints_by_section
  }
end