Class: Ea::Spa::Configuration
- Inherits:
-
Object
- Object
- Ea::Spa::Configuration
- Defined in:
- lib/ea/spa/configuration.rb
Overview
SPA-side configuration. A YAML file with the shape:
metadata:
title: ...
description: ...
version: ...
author: ...
license: ...
homepage: ...
repository: ...
ui:
title: ...
description: ...
Values under metadata override fields on the model's
Ea::Model::Metadata. Values under ui (and other sections
like appearance) are surfaced to the SPA view via the
skeleton's metadata hash so the frontend can use them.
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #appearance ⇒ Object
-
#apply_to_metadata(model_metadata) ⇒ Object
Apply overrides to a model Metadata instance, returning a new one.
-
#initialize(path, data) ⇒ Configuration
constructor
A new instance of Configuration.
- #metadata_override ⇒ Object
-
#render_diagrams? ⇒ Boolean
Diagram rendering control.
- #ui ⇒ Object
-
#view_extras ⇒ Object
Surface the relevant config (ui, appearance, diagrams) into a hash the SPA skeleton embeds in its metadata payload so the frontend can hide its diagram UI when disabled.
Constructor Details
#initialize(path, data) ⇒ Configuration
Returns a new instance of Configuration.
37 38 39 40 |
# File 'lib/ea/spa/configuration.rb', line 37 def initialize(path, data) @path = path @data = data.is_a?(Hash) ? data : {} end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
26 27 28 |
# File 'lib/ea/spa/configuration.rb', line 26 def data @data end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
26 27 28 |
# File 'lib/ea/spa/configuration.rb', line 26 def path @path end |
Class Method Details
.load(path) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/ea/spa/configuration.rb', line 28 def self.load(path) return nil if path.nil? || path.empty? unless File.exist?(path) raise ArgumentError, "SPA config not found: #{path}" end new(path, YAML.safe_load(File.read(path)) || {}) end |
Instance Method Details
#appearance ⇒ Object
50 51 52 |
# File 'lib/ea/spa/configuration.rb', line 50 def appearance @data["appearance"] || {} end |
#apply_to_metadata(model_metadata) ⇒ Object
Apply overrides to a model Metadata instance, returning a new one. The original is left untouched.
67 68 69 70 71 72 73 |
# File 'lib/ea/spa/configuration.rb', line 67 def () return unless merged = () .merge(stringify_keys()) (merged) end |
#metadata_override ⇒ Object
42 43 44 |
# File 'lib/ea/spa/configuration.rb', line 42 def (@data["metadata"] || {}).transform_keys(&:to_sym) end |
#render_diagrams? ⇒ Boolean
Diagram rendering control. Default: true (preserve historical
behavior). Set diagrams.enabled: false in the YAML to skip
diagram shards entirely — useful when the renderer output is
not yet production-quality and you'd rather hide diagrams
than ship broken visuals.
59 60 61 62 63 |
# File 'lib/ea/spa/configuration.rb', line 59 def render_diagrams? diagrams_cfg = @data["diagrams"].is_a?(Hash) ? @data["diagrams"] : {} enabled = diagrams_cfg.key?("enabled") ? diagrams_cfg["enabled"] : true enabled != false end |
#ui ⇒ Object
46 47 48 |
# File 'lib/ea/spa/configuration.rb', line 46 def ui @data["ui"] || {} end |
#view_extras ⇒ Object
Surface the relevant config (ui, appearance, diagrams) into a hash the SPA skeleton embeds in its metadata payload so the frontend can hide its diagram UI when disabled.
78 79 80 81 82 |
# File 'lib/ea/spa/configuration.rb', line 78 def view_extras extras = { "ui" => ui, "appearance" => appearance } extras["diagrams"] = { "enabled" => render_diagrams? } extras.reject { |_, v| v.nil? || v.empty? } end |