Class: Ea::Spa::Generator
- Inherits:
-
Object
- Object
- Ea::Spa::Generator
- Defined in:
- lib/ea/spa/generator.rb
Overview
Orchestrator: takes an Ea::Model::Document and an output mode, dispatches to the matching Output::Strategy. Single source of truth for which modes exist; new modes = one entry in OUTPUT_STRATEGIES.
Constant Summary collapse
- OUTPUT_STRATEGIES =
{ single_file: Output::SingleFileStrategy, sharded: Output::ShardedMultiFileStrategy }.freeze
- DEFAULT_MODE =
:single_file
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#output_path ⇒ Object
readonly
Returns the value of attribute output_path.
-
#shard_url_for ⇒ Object
readonly
Returns the value of attribute shard_url_for.
Instance Method Summary collapse
- #generate ⇒ Object
-
#initialize(document, output:, mode: nil, shard_url_for: nil, configuration: nil) ⇒ Generator
constructor
A new instance of Generator.
- #projector ⇒ Object
- #strategy_class ⇒ Object
Constructor Details
#initialize(document, output:, mode: nil, shard_url_for: nil, configuration: nil) ⇒ Generator
Returns a new instance of Generator.
19 20 21 22 23 24 25 26 |
# File 'lib/ea/spa/generator.rb', line 19 def initialize(document, output:, mode: nil, shard_url_for: nil, configuration: nil) @document = document @output_path = output @mode = (mode || DEFAULT_MODE).to_sym @shard_url_for = shard_url_for @configuration = configuration end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
17 18 19 |
# File 'lib/ea/spa/generator.rb', line 17 def configuration @configuration end |
#document ⇒ Object (readonly)
Returns the value of attribute document.
17 18 19 |
# File 'lib/ea/spa/generator.rb', line 17 def document @document end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
17 18 19 |
# File 'lib/ea/spa/generator.rb', line 17 def mode @mode end |
#output_path ⇒ Object (readonly)
Returns the value of attribute output_path.
17 18 19 |
# File 'lib/ea/spa/generator.rb', line 17 def output_path @output_path end |
#shard_url_for ⇒ Object (readonly)
Returns the value of attribute shard_url_for.
17 18 19 |
# File 'lib/ea/spa/generator.rb', line 17 def shard_url_for @shard_url_for end |
Instance Method Details
#generate ⇒ Object
28 29 30 |
# File 'lib/ea/spa/generator.rb', line 28 def generate strategy_class.new(output_path).render(projector) end |
#projector ⇒ Object
32 33 34 35 36 |
# File 'lib/ea/spa/generator.rb', line 32 def projector @projector ||= Projector.new(document, shard_url_for: shard_url_for, configuration: configuration) end |
#strategy_class ⇒ Object
38 39 40 41 42 |
# File 'lib/ea/spa/generator.rb', line 38 def strategy_class OUTPUT_STRATEGIES[mode] || raise(ArgumentError, "Unknown SPA mode: #{mode.inspect}. " \ "Use :single_file or :sharded.") end |