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 =

Returns Filename for the main settings file.

Returns:

  • (String)

    Filename for the main settings file.

'settings.json'
LOCAL_SETTINGS_FILE =

Returns Filename for the local settings override file.

Returns:

  • (String)

    Filename for the local settings override file.

'settings.local.json'
BEHAVIOUR_DIR =

Returns Relative path to the behaviour configuration directory.

Returns:

  • (String)

    Relative path to the behaviour configuration directory.

'conf/behaviour'
SCHEMA_DIR =

Returns Relative path to the JSON Schema directory.

Returns:

  • (String)

    Relative path to the JSON Schema directory.

'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



29
30
31
# File 'lib/rosett_ai/configuration.rb', line 29

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.



22
23
24
# File 'lib/rosett_ai/configuration.rb', line 22

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)



57
58
59
# File 'lib/rosett_ai/configuration.rb', line 57

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/



64
65
66
# File 'lib/rosett_ai/configuration.rb', line 64

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)



43
44
45
# File 'lib/rosett_ai/configuration.rb', line 43

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)



50
51
52
# File 'lib/rosett_ai/configuration.rb', line 50

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

#reload!void

This method returns an undefined value.

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



78
79
80
81
82
83
# File 'lib/rosett_ai/configuration.rb', line 78

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/



71
72
73
# File 'lib/rosett_ai/configuration.rb', line 71

def schema_path
  root_path.join(SCHEMA_DIR)
end

#settingsHash

Returns the parsed global settings from settings.json.

Returns:

  • (Hash)

    global settings hash (memoized)



36
37
38
# File 'lib/rosett_ai/configuration.rb', line 36

def settings
  @settings ||= load_settings
end