Class: Raykit::Configuration
- Inherits:
-
Object
- Object
- Raykit::Configuration
- Defined in:
- lib/raykit/configuration.rb
Constant Summary collapse
- CONFIG_DIR =
Define a subdirectory and filename for the config file in a cross-platform manner.
File.join(Dir.home, ".config", "raykit")
- CONFIG_FILE =
File.join(CONFIG_DIR, "config.json")
Instance Attribute Summary collapse
-
#auto_setup ⇒ Object
Returns the value of attribute auto_setup.
-
#backup_dir ⇒ Object
Returns the value of attribute backup_dir.
-
#log_level ⇒ Object
Returns the value of attribute log_level.
-
#root_dir ⇒ Object
Returns the value of attribute root_dir.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #load_configuration ⇒ Object
- #save_configuration ⇒ Object
- #set_default_configuration ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/raykit/configuration.rb', line 11 def initialize if File.exist?(CONFIG_FILE) load_configuration else set_default_configuration if (!Dir.exist?(CONFIG_DIR)) save_configuration # Save the default configuration if no configuration file exists. end end end |
Instance Attribute Details
#auto_setup ⇒ Object
Returns the value of attribute auto_setup.
5 6 7 |
# File 'lib/raykit/configuration.rb', line 5 def auto_setup @auto_setup end |
#backup_dir ⇒ Object
Returns the value of attribute backup_dir.
5 6 7 |
# File 'lib/raykit/configuration.rb', line 5 def backup_dir @backup_dir end |
#log_level ⇒ Object
Returns the value of attribute log_level.
5 6 7 |
# File 'lib/raykit/configuration.rb', line 5 def log_level @log_level end |
#root_dir ⇒ Object
Returns the value of attribute root_dir.
5 6 7 |
# File 'lib/raykit/configuration.rb', line 5 def root_dir @root_dir end |
Instance Method Details
#load_configuration ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/raykit/configuration.rb', line 22 def load_configuration config_data = JSON.parse(File.read(CONFIG_FILE)) @root_dir = config_data["root_dir"] @auto_setup = config_data["auto_setup"] @backup_dir = config_data["backup_dir"] @log_level = config_data["log_level"] end |
#save_configuration ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/raykit/configuration.rb', line 37 def save_configuration # Create the config directory if it doesn't exist. FileUtils.mkdir_p(CONFIG_DIR) unless Dir.exist?(CONFIG_DIR) File.write(CONFIG_FILE, { root_dir: @root_dir, auto_setup: @auto_setup, backup_dir: @backup_dir, log_level: @log_level, }.to_json) end |
#set_default_configuration ⇒ Object
30 31 32 33 34 35 |
# File 'lib/raykit/configuration.rb', line 30 def set_default_configuration @root_dir = "" @auto_setup = false @backup_dir = "backup" @log_level = ::Logger::DEBUG end |
#to_s ⇒ Object
49 50 51 |
# File 'lib/raykit/configuration.rb', line 49 def to_s "Root Directory: #{@root_dir}\nAuto Setup: #{@auto_setup}\nBackup Directory: #{@backup_dir}" end |