Class: InitEnv::Config
- Inherits:
-
Object
- Object
- InitEnv::Config
- Defined in:
- lib/mk_semi_lattice/init_env.rb
Class Method Summary collapse
-
.conf ⇒ Object
needed, failed by attr_reader, private?.
- .conf_path ⇒ Object
- .config_dir ⇒ Object
- .load_conf ⇒ Object
- .log_enabled? ⇒ Boolean
- .log_path ⇒ Object
- .save_conf ⇒ Object
- .set_log(value) ⇒ Object
- .setup ⇒ Object
Class Method Details
.conf ⇒ Object
needed, failed by attr_reader, private?
40 41 42 |
# File 'lib/mk_semi_lattice/init_env.rb', line 40 def self.conf # needed, failed by attr_reader, private? @conf end |
.conf_path ⇒ Object
48 49 50 |
# File 'lib/mk_semi_lattice/init_env.rb', line 48 def self.conf_path File.join(config_dir, "semi_lattice.conf") end |
.config_dir ⇒ Object
44 45 46 |
# File 'lib/mk_semi_lattice/init_env.rb', line 44 def self.config_dir ENV['SEMI_LATTICE_CONFIG_DIR'] || File.("~/.config/semi_lattice") end |
.load_conf ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/mk_semi_lattice/init_env.rb', line 66 def load_conf if File.file?(conf_path) begin loaded = YAML.load_file(conf_path) if loaded.is_a?(Hash) @conf.merge!(loaded) else puts "Warning: #{conf_path} is not a hash. Using default config.".yellow end rescue puts "Warning: #{conf_path} is invalid. Using default config.".yellow end end end |
.log_enabled? ⇒ Boolean
85 86 87 |
# File 'lib/mk_semi_lattice/init_env.rb', line 85 def log_enabled? @conf["log"] end |
.log_path ⇒ Object
52 53 54 |
# File 'lib/mk_semi_lattice/init_env.rb', line 52 def self.log_path File.join(config_dir, "semi_lattice_history") end |
.save_conf ⇒ Object
81 82 83 |
# File 'lib/mk_semi_lattice/init_env.rb', line 81 def save_conf File.write(conf_path, @conf.to_yaml) end |
.set_log(value) ⇒ Object
89 90 91 92 |
# File 'lib/mk_semi_lattice/init_env.rb', line 89 def set_log(value) @conf["log"] = value save_conf end |
.setup ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/mk_semi_lattice/init_env.rb', line 57 def setup FileUtils.mkdir_p(config_dir) if File.file?(conf_path) load_conf else save_conf end end |