Class: RailsApiDocs::Doc::FileBuilder
- Inherits:
-
Object
- Object
- RailsApiDocs::Doc::FileBuilder
- Defined in:
- lib/rails-api-docs/doc/file_builder.rb
Overview
Reads the YAML config and writes the rendered HTML to disk. Used by ‘rake rails-api-docs:build`. Extracted as a service so the rake task body can stay tiny and the build flow is unit-testable.
Defined Under Namespace
Classes: MissingConfigError
Instance Method Summary collapse
-
#call ⇒ Object
Writes the HTML and returns the absolute output path.
-
#initialize(config_path:, output_path:) ⇒ FileBuilder
constructor
A new instance of FileBuilder.
Constructor Details
#initialize(config_path:, output_path:) ⇒ FileBuilder
Returns a new instance of FileBuilder.
13 14 15 16 |
# File 'lib/rails-api-docs/doc/file_builder.rb', line 13 def initialize(config_path:, output_path:) @config_path = config_path @output_path = output_path end |
Instance Method Details
#call ⇒ Object
Writes the HTML and returns the absolute output path.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rails-api-docs/doc/file_builder.rb', line 19 def call unless File.exist?(@config_path) raise MissingConfigError, "Config file not found at #{@config_path}. " \ "Run `rails g rails-api-docs:init` first." end config = Config::Loader.load(@config_path) html = Renderer.new(config).call FileUtils.mkdir_p(File.dirname(@output_path)) File.write(@output_path, html) @output_path end |