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.
-
#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 |
#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 |
# 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"] end |
#save_configuration ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/raykit/configuration.rb', line 35 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, }.to_json) end |
#set_default_configuration ⇒ Object
29 30 31 32 33 |
# File 'lib/raykit/configuration.rb', line 29 def set_default_configuration @root_dir = "" @auto_setup = false @backup_dir = "backup" end |
#to_s ⇒ Object
46 47 48 |
# File 'lib/raykit/configuration.rb', line 46 def to_s "Root Directory: #{@root_dir}\nAuto Setup: #{@auto_setup}\nBackup Directory: #{@backup_dir}" end |