Class: ShinseiConfig::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/shinsei_config/loader.rb

Overview

Handles loading YAML files with ERB interpolation and environment splitting

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_path:, env: nil, **yaml_opts) ⇒ Loader



19
20
21
22
23
# File 'lib/shinsei_config/loader.rb', line 19

def initialize(config_path:, env: nil, **yaml_opts)
  @config_path = config_path
  @env = env
  @yaml_opts = yaml_opts
end

Instance Attribute Details

#config_pathObject (readonly)

Returns the value of attribute config_path.



16
17
18
# File 'lib/shinsei_config/loader.rb', line 16

def config_path
  @config_path
end

#envObject (readonly)

Returns the value of attribute env.



16
17
18
# File 'lib/shinsei_config/loader.rb', line 16

def env
  @env
end

#yaml_optsObject (readonly)

Returns the value of attribute yaml_opts.



16
17
18
# File 'lib/shinsei_config/loader.rb', line 16

def yaml_opts
  @yaml_opts
end

Instance Method Details

#loadObject

Raises:



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/shinsei_config/loader.rb', line 26

def load
  raise Error, "Config file not found: #{config_path}" unless File.exist?(config_path)

  # Read raw content
  raw_content = File.read(config_path)

  # Process ERB on raw content before YAML parsing
  erb_processed = ERB.new(raw_content).result

  # Parse YAML with provided options
  parsed_yaml = YAML.safe_load(erb_processed, **yaml_opts)

  # Extract environment section if env is set
  extract_env_section(parsed_yaml)
end