Class: LightTr::Config
- Inherits:
-
Object
- Object
- LightTr::Config
- Defined in:
- lib/light_tr/config.rb
Defined Under Namespace
Classes: SetConfigError
Class Method Summary collapse
- .api_key ⇒ Object
- .clear ⇒ Object
- .config_exists? ⇒ Boolean
- .config_file ⇒ Object
- .config_missing? ⇒ Boolean
- .config_path ⇒ Object
- .get ⇒ Object
- .languages ⇒ Object
- .model ⇒ Object
- .open_ai_key ⇒ Object
- .provider ⇒ Object
- .set(hash) ⇒ Object
Class Method Details
.api_key ⇒ Object
20 21 22 23 24 |
# File 'lib/light_tr/config.rb', line 20 def self.api_key get['api_key'] || raise('Google Translation API key missing. Try to update configuration via `trans -config`') master_key = get['master_key'] || raise('Config file corrupted. Try to update configuration via `trans -config`') Lockbox.new(key: master_key).decrypt(get['api_key']) end |
.clear ⇒ Object
63 64 65 |
# File 'lib/light_tr/config.rb', line 63 def self.clear File.write(config_file, {}.to_yaml) end |
.config_exists? ⇒ Boolean
38 39 40 |
# File 'lib/light_tr/config.rb', line 38 def self.config_exists? File.exist?(config_file) end |
.config_file ⇒ Object
46 47 48 |
# File 'lib/light_tr/config.rb', line 46 def self.config_file File.('.config', config_path) end |
.config_missing? ⇒ Boolean
42 43 44 |
# File 'lib/light_tr/config.rb', line 42 def self.config_missing? !config_exists? end |
.config_path ⇒ Object
34 35 36 |
# File 'lib/light_tr/config.rb', line 34 def self.config_path File.join(Dir.home, '.light_tr') end |
.get ⇒ Object
50 51 52 53 54 |
# File 'lib/light_tr/config.rb', line 50 def self.get return load_configuration if config_exists? {} end |
.languages ⇒ Object
10 11 12 |
# File 'lib/light_tr/config.rb', line 10 def self.languages get['languages'] end |
.model ⇒ Object
30 31 32 |
# File 'lib/light_tr/config.rb', line 30 def self.model get['model'] || 'gpt-3.5-turbo' end |
.open_ai_key ⇒ Object
14 15 16 17 18 |
# File 'lib/light_tr/config.rb', line 14 def self.open_ai_key get['open_ai_key'] || raise('OpenAI API key missing. Try to update configuration via `trans -config`') master_key = get['master_key'] || raise('Config file corrupted. Try to update configuration via `trans -config`') Lockbox.new(key: master_key).decrypt(get['open_ai_key']) end |
.provider ⇒ Object
26 27 28 |
# File 'lib/light_tr/config.rb', line 26 def self.provider get['provider'] || 'google' end |
.set(hash) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/light_tr/config.rb', line 56 def self.set(hash) raise SetConfigError, 'argument is not kind of hash' unless hash.kind_of?(Hash) updated_config = get.merge(hash) save_configuration(updated_config) end |