Class: Ea::Spa::Configuration

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

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

#dataObject (readonly)

Returns the value of attribute data.



26
27
28
# File 'lib/ea/spa/configuration.rb', line 26

def data
  @data
end

#pathObject (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

#appearanceObject



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_overrideObject



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.

Returns:

  • (Boolean)


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

#uiObject



46
47
48
# File 'lib/ea/spa/configuration.rb', line 46

def ui
  @data["ui"] || {}
end

#view_extrasObject

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