Class: RailsApiDocs::Config::Appender
- Inherits:
-
Object
- Object
- RailsApiDocs::Config::Appender
- 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
- #call ⇒ Object
- #changes? ⇒ Boolean
-
#diff ⇒ Object
{ new_sections: [keys…], new_endpoints_by_section: { key => [endpoints…] } }.
-
#initialize(existing:, generated:) ⇒ Appender
constructor
A new instance of Appender.
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
#call ⇒ Object
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
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 |
#diff ⇒ Object
{ 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 |