Class: WritersRoom::Config
- Inherits:
-
Object
- Object
- WritersRoom::Config
- Defined in:
- lib/writers_room/config.rb
Constant Summary collapse
- DEFAULT_CONFIG =
{ "provider" => "ollama", "model_name" => "gpt-oss", }.freeze
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
-
.create_project(project_path, options = {}) ⇒ WritersRoom::Config
Create a new project configuration.
Instance Method Summary collapse
-
#get(key) ⇒ Object
Get configuration value.
-
#initialize(path = nil) ⇒ Config
constructor
A new instance of Config.
-
#load_config ⇒ Hash
Load configuration from file.
-
#model_name ⇒ String
Get model name.
-
#provider ⇒ String
Get provider.
-
#save(config_data = @data) ⇒ Boolean
Save configuration to file.
-
#set(key, value) ⇒ Object
Set configuration value.
Constructor Details
#initialize(path = nil) ⇒ Config
15 16 17 18 |
# File 'lib/writers_room/config.rb', line 15 def initialize(path = nil) @path = path || default_config_path @data = load_config end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
8 9 10 |
# File 'lib/writers_room/config.rb', line 8 def data @data end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
8 9 10 |
# File 'lib/writers_room/config.rb', line 8 def path @path end |
Class Method Details
.create_project(project_path, options = {}) ⇒ WritersRoom::Config
Create a new project configuration
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/writers_room/config.rb', line 51 def self.create_project(project_path, = {}) FileUtils.mkdir_p(project_path) config_path = File.join(project_path, "config.yml") config_data = DEFAULT_CONFIG.merge(.transform_keys(&:to_s)) config = new(config_path) config.save(config_data) config end |
Instance Method Details
#get(key) ⇒ Object
Get configuration value
66 67 68 |
# File 'lib/writers_room/config.rb', line 66 def get(key) @data[key.to_s] end |
#load_config ⇒ Hash
Load configuration from file
23 24 25 26 27 28 29 30 |
# File 'lib/writers_room/config.rb', line 23 def load_config return DEFAULT_CONFIG.dup unless File.exist?(path) YAML.load_file(path) || DEFAULT_CONFIG.dup rescue StandardError => e warn "Error loading config from #{path}: #{e.message}" DEFAULT_CONFIG.dup end |
#model_name ⇒ String
Get model name
88 89 90 |
# File 'lib/writers_room/config.rb', line 88 def model_name get("model_name") end |
#provider ⇒ String
Get provider
81 82 83 |
# File 'lib/writers_room/config.rb', line 81 def provider get("provider") end |
#save(config_data = @data) ⇒ Boolean
Save configuration to file
36 37 38 39 40 41 42 43 44 |
# File 'lib/writers_room/config.rb', line 36 def save(config_data = @data) FileUtils.mkdir_p(File.dirname(path)) File.write(path, YAML.dump(config_data)) @data = config_data true rescue StandardError => e warn "Error saving config to #{path}: #{e.message}" false end |
#set(key, value) ⇒ Object
Set configuration value
74 75 76 |
# File 'lib/writers_room/config.rb', line 74 def set(key, value) @data[key.to_s] = value end |