Module: HatiConfig::Configuration::Local

Defined in:
lib/hati_config/configuration.rb

Overview

Isolated module provides methods for handling isolated configurations.

Instance Method Summary collapse

Instance Method Details

#configure(config_tree_name, opts = {}) { ... } ⇒ self

Configures an isolated config tree and tracks it

Examples:

configure :isolated_settings do
  config api_url: "https://api.example.com"
end

# Example of accessing the configuration
puts MyApp.isolated_settings.api_url # => "https://api.example.com"

Parameters:

  • config_tree_name (Symbol) —

    The name of the configuration tree

  • opts (Hash) (defaults to: {}) —

    Options for configuration

Yields:

  • The configuration block

Returns:

  • (self)


23
24
25
26
27
28
29
30
# File 'lib/hati_config/configuration.rb', line 23

def configure(config_tree_name, opts = {}, &block)
  super

  @isolated_configs ||= []
  @isolated_configs << config_tree_name

  self
end

#inherited(base) ⇒ Object

Inherits isolated configurations to the base class

Examples:

class ChildClass < ParentClass
  # Automatically inherits isolated configurations
end

# Example of accessing inherited configurations
puts ChildClass.parent_settings.timeout # => 30

Parameters:

  • base (Class) —

    The inheriting class



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/hati_config/configuration.rb', line 43

def inherited(base)
  super

  @isolated_configs.each do |parent_config|
    hash = __send__(parent_config).to_h
    schema = __send__(parent_config).type_schema
    lock_schema = __send__(parent_config).lock_schema

    base.configure parent_config, hash: hash, schema: schema, lock_schema: lock_schema
  end
end