Class: Lutaml::Ea::Diagram::Configuration
- Inherits:
-
Object
- Object
- Lutaml::Ea::Diagram::Configuration
- Defined in:
- lib/lutaml/ea/diagram/configuration.rb
Overview
Configuration management for diagram styling
This class provides hierarchical style resolution with the following priority:
-
EA Data (QEA/XMI) - Highest priority
-
Class-specific overrides (user config)
-
Package-based styling (wildcard support)
-
Stereotype-based styling
-
Global defaults - Lowest priority
Constant Summary collapse
- DEFAULT_CONFIG_PATHS =
Default configuration file paths in order of preference
[ "config/diagram_styles.yml", File.("~/.lutaml/diagram_styles.yml"), ].freeze
Instance Attribute Summary collapse
-
#config_data ⇒ Object
readonly
Returns the value of attribute config_data.
Instance Method Summary collapse
-
#connector_style(connector_type, property) ⇒ Object
Get connector style.
-
#initialize(config_path = nil) ⇒ Configuration
constructor
Initialize configuration with optional custom path.
-
#legend_config ⇒ Hash
Get legend configuration.
-
#style_for(element, property) ⇒ Object
Get style for a specific element.
-
#to_h ⇒ Hash
Get the entire configuration data.
Constructor Details
#initialize(config_path = nil) ⇒ Configuration
Initialize configuration with optional custom path
34 35 36 |
# File 'lib/lutaml/ea/diagram/configuration.rb', line 34 def initialize(config_path = nil) @config_data = load_configuration(config_path) end |
Instance Attribute Details
#config_data ⇒ Object (readonly)
Returns the value of attribute config_data.
23 24 25 |
# File 'lib/lutaml/ea/diagram/configuration.rb', line 23 def config_data @config_data end |
Instance Method Details
#connector_style(connector_type, property) ⇒ Object
Get connector style
Type of connector (generalization, association, etc.)
107 108 109 |
# File 'lib/lutaml/ea/diagram/configuration.rb', line 107 def connector_style(connector_type, property) dig_config("connectors.#{connector_type}.#{property}") end |
#legend_config ⇒ Hash
Get legend configuration
114 115 116 |
# File 'lib/lutaml/ea/diagram/configuration.rb', line 114 def legend_config config_data["legend"] || {} end |
#style_for(element, property) ⇒ Object
Get style for a specific element
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/lutaml/ea/diagram/configuration.rb', line 43 def style_for(element, property) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity return nil if property.nil? || property.empty? # Priority: Class-specific > Package > Stereotype > Defaults value = nil # 1. Try class-specific override (highest priority) if element.respond_to?(:name) && element.name class_config = dig_config("classes.#{element.name}.#{property}") value = class_config if class_config end # 2. Try package-based styling if !value && element.respond_to?(:package_name) && element.package_name # Support wildcards: "CityGML::*" package_configs = config_data["packages"] || {} package_configs.each do |pattern, pkg_config| if matches_package?(element.package_name, pattern) pkg_value = dig_hash(pkg_config, property) value = pkg_value if pkg_value break end end end # 3. Try stereotype-based styling if !value && element.respond_to?(:stereotype) && element.stereotype stereotypes = Array(element.stereotype) stereotypes.each do |stereo| stereo_value = dig_config("stereotypes.#{stereo}.#{property}") if stereo_value value = stereo_value break end end end # 4. Fall back to defaults (lowest priority) # Handle property name aliases # (e.g., "colors.fill" -> "colors.default_fill") unless value value = dig_config("defaults.#{property}") # If not found, try with "default_" prefix for certain properties unless value if property.start_with?("colors.fill") value = dig_config("defaults.colors.default_fill") elsif property.start_with?("colors.stroke") && !property.include?("stroke_") value = dig_config("defaults.colors.default_stroke") end end end value end |
#to_h ⇒ Hash
Get the entire configuration data
121 122 123 |
# File 'lib/lutaml/ea/diagram/configuration.rb', line 121 def to_h config_data end |