Class: Lutaml::Qea::Services::Configuration

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

Examples:

Load configuration

config = Configuration.load
tables = config.enabled_tables

Get table configuration

table_cfg = config.table_config_for("t_object")

Defined Under Namespace

Classes: ColumnDefinition, NullHandling, TableDefinition

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.default_config_pathString

Get default configuration file path

Returns:

  • (String)

    Path to default config file



129
130
131
# File 'lib/lutaml/qea/services/configuration.rb', line 129

def default_config_path
  File.expand_path("../../../../config/qea_schema.yml", __dir__)
end

.load(config_path = nil) ⇒ Configuration

Load configuration from YAML file

Parameters:

  • config_path (String, nil) (defaults to: nil)

    Path to configuration file Defaults to config/qea_schema.yml

Returns:

Raises:

  • (Errno::ENOENT)

    if config file not found

  • (Lutaml::Model::Error)

    if YAML is invalid



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

Parameters:

  • field_name (String)

    The field name

Returns:

  • (Boolean)

    true if field is in boolean_fields list



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

Parameters:

  • table_name (String)

    The table name

Returns:

  • (String, nil)

    The collection name



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

Parameters:

  • value (String, nil)

    The value to convert

Returns:

  • (String, nil)

    The converted value



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_namesArray<String>

Get all enabled table names

Returns:

  • (Array<String>)

    Array of 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_tablesArray<TableDefinition>

Get list of enabled tables

Returns:



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

Parameters:

  • table_name (String)

    The table name

Returns:

  • (String, nil)

    The primary key column name



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

Parameters:

  • table_name (String)

    The table name

Returns:



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

Parameters:

  • table_name (String)

    The table name

Returns:

  • (Boolean)

    true if 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

Returns:

  • (Boolean)

    true if zero should be converted to nil



205
206
207
# File 'lib/lutaml/qea/services/configuration.rb', line 205

def zero_as_null?
  null_handling&.zero_as_null == true
end