Class: Lutaml::Qea::Services::Configuration
- Inherits:
-
Model::Serializable
- Object
- Model::Serializable
- Lutaml::Qea::Services::Configuration
- Defined in:
- lib/lutaml/qea/services/configuration.rb
Overview
Configuration service loads and provides configuration from YAML file.
This service uses lutaml-model for YAML parsing and provides access to QEA schema configuration including table definitions, type mappings, and transformation rules.
Defined Under Namespace
Classes: ColumnDefinition, NullHandling, TableDefinition
Class Method Summary collapse
-
.default_config_path ⇒ String
Get default configuration file path.
-
.load(config_path = nil) ⇒ Configuration
Load configuration from YAML file.
Instance Method Summary collapse
-
#boolean_field?(field_name) ⇒ Boolean
Check if a field should be treated as boolean.
-
#collection_name_for(table_name) ⇒ String?
Get collection name for a table.
-
#convert_empty_string(value) ⇒ String?
Convert empty strings to nil based on configuration.
-
#enabled_table_names ⇒ Array<String>
Get all enabled table names.
-
#enabled_tables ⇒ Array<TableDefinition>
Get list of enabled tables.
-
#primary_key_for(table_name) ⇒ String?
Get primary key for a table.
-
#table_config_for(table_name) ⇒ TableDefinition?
Get table configuration by table name.
-
#table_enabled?(table_name) ⇒ Boolean
Check if a table is enabled.
-
#zero_as_null? ⇒ Boolean
Check if zero should be treated as null.
Class Method Details
.default_config_path ⇒ String
Get default configuration file path
129 130 131 |
# File 'lib/lutaml/qea/services/configuration.rb', line 129 def default_config_path File.("../../../../config/qea_schema.yml", __dir__) end |
.load(config_path = nil) ⇒ Configuration
Load configuration from YAML file
114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/lutaml/qea/services/configuration.rb', line 114 def load(config_path = nil) config_path ||= default_config_path unless File.exist?(config_path) raise Errno::ENOENT, "Configuration file not found: #{config_path}" end yaml_content = File.read(config_path) from_yaml(yaml_content) end |
Instance Method Details
#boolean_field?(field_name) ⇒ Boolean
Check if a field should be treated as boolean
170 171 172 |
# File 'lib/lutaml/qea/services/configuration.rb', line 170 def boolean_field?(field_name) boolean_fields&.include?(field_name) || false end |
#collection_name_for(table_name) ⇒ String?
Get collection name for a table
187 188 189 190 |
# File 'lib/lutaml/qea/services/configuration.rb', line 187 def collection_name_for(table_name) table = table_config_for(table_name) table&.collection_name end |
#convert_empty_string(value) ⇒ String?
Convert empty strings to nil based on configuration
196 197 198 199 200 |
# File 'lib/lutaml/qea/services/configuration.rb', line 196 def convert_empty_string(value) return value unless null_handling&.empty_string_as_null value.nil? || value.empty? ? nil : value end |
#enabled_table_names ⇒ Array<String>
Get all enabled table names
162 163 164 |
# File 'lib/lutaml/qea/services/configuration.rb', line 162 def enabled_table_names enabled_tables.map(&:table_name) end |
#enabled_tables ⇒ Array<TableDefinition>
Get list of enabled tables
137 138 139 |
# File 'lib/lutaml/qea/services/configuration.rb', line 137 def enabled_tables tables&.select(&:enabled) || [] end |
#primary_key_for(table_name) ⇒ String?
Get primary key for a table
178 179 180 181 |
# File 'lib/lutaml/qea/services/configuration.rb', line 178 def primary_key_for(table_name) table = table_config_for(table_name) table&.primary_key end |
#table_config_for(table_name) ⇒ TableDefinition?
Get table configuration by table name
or nil if not found
146 147 148 |
# File 'lib/lutaml/qea/services/configuration.rb', line 146 def table_config_for(table_name) tables&.find { |t| t.table_name == table_name } end |
#table_enabled?(table_name) ⇒ Boolean
Check if a table is enabled
154 155 156 157 |
# File 'lib/lutaml/qea/services/configuration.rb', line 154 def table_enabled?(table_name) table = table_config_for(table_name) table&.enabled == true end |
#zero_as_null? ⇒ Boolean
Check if zero should be treated as null
205 206 207 |
# File 'lib/lutaml/qea/services/configuration.rb', line 205 def zero_as_null? null_handling&.zero_as_null == true end |