Class: RosettAi::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/rosett_ai/configuration.rb

Overview

Manages hierarchical configuration for Rosett-AI Supports global -> group -> project configuration inheritance

Constant Summary collapse

SETTINGS_FILE =
'settings.json'
LOCAL_SETTINGS_FILE =
'settings.local.json'
BEHAVIOUR_DIR =
'conf/behaviour'
SCHEMA_DIR =
'conf/schemas'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root_path: nil) ⇒ Configuration

Initializes a new Configuration instance.

Parameters:

  • root_path (String, Pathname, nil) (defaults to: nil)

    path to the Rosett-AI root directory; defaults to RosettAi.root when nil



25
26
27
# File 'lib/rosett_ai/configuration.rb', line 25

def initialize(root_path: nil)
  @root_path = resolve_root_path(root_path)
end

Instance Attribute Details

#root_pathObject (readonly)

Returns the value of attribute root_path.



18
19
20
# File 'lib/rosett_ai/configuration.rb', line 18

def root_path
  @root_path
end

Instance Method Details

#behaviour_filesArray<String>

Returns the list of behaviour YAML files found in the behaviour directory.

Returns:

  • (Array<String>)

    absolute paths to behaviour YAML files (memoized)



53
54
55
# File 'lib/rosett_ai/configuration.rb', line 53

def behaviour_files
  @behaviour_files ||= Dir.glob(behaviour_path.join('*.yml'))
end

#behaviour_pathPathname

Returns the path to the behaviour configuration directory.

Returns:

  • (Pathname)

    path to conf/behaviour/



60
61
62
# File 'lib/rosett_ai/configuration.rb', line 60

def behaviour_path
  root_path.join(BEHAVIOUR_DIR)
end

#local_settingsHash

Returns the parsed local overrides from settings.local.json.

Returns:

  • (Hash)

    local settings hash (memoized)



39
40
41
# File 'lib/rosett_ai/configuration.rb', line 39

def local_settings
  @local_settings ||= load_local_settings
end

#merged_settingsHash

Returns global settings deep-merged with local overrides.

Returns:

  • (Hash)

    merged settings hash (memoized)



46
47
48
# File 'lib/rosett_ai/configuration.rb', line 46

def merged_settings
  @merged_settings ||= deep_merge(settings, local_settings)
end

#reload!

This method returns an undefined value.

Clears all memoized state so the next access re-reads from disk.



74
75
76
77
78
79
# File 'lib/rosett_ai/configuration.rb', line 74

def reload!
  @settings = nil
  @local_settings = nil
  @merged_settings = nil
  @behaviour_files = nil
end

#schema_pathPathname

Returns the path to the JSON Schema directory.

Returns:

  • (Pathname)

    path to conf/schemas/



67
68
69
# File 'lib/rosett_ai/configuration.rb', line 67

def schema_path
  root_path.join(SCHEMA_DIR)
end

#settingsHash

Returns the parsed global settings from settings.json.

Returns:

  • (Hash)

    global settings hash (memoized)



32
33
34
# File 'lib/rosett_ai/configuration.rb', line 32

def settings
  @settings ||= load_settings
end