Class: Solis::ConfigFile
- Inherits:
-
Object
- Object
- Solis::ConfigFile
- Defined in:
- lib/solis/config_file.rb
Class Method Summary collapse
- .[](key) ⇒ Object
- .[]=(key, value) ⇒ Object
- .config ⇒ Object
- .discover_config_file_path ⇒ Object
- .include?(key) ⇒ Boolean
- .init ⇒ Object
- .keys ⇒ Object
- .name ⇒ Object
- .name=(config_file_name) ⇒ Object
- .path ⇒ Object
- .path=(config_file_path) ⇒ Object
- .process(config) ⇒ Object
- .version ⇒ Object
Class Method Details
.[](key) ⇒ Object
31 32 33 34 |
# File 'lib/solis/config_file.rb', line 31 def self.[](key) init @config[key] end |
.[]=(key, value) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/solis/config_file.rb', line 36 def self.[]=(key,value) init @config[key] = value File.open("#{path}/#{name}", 'w') do |f| f.puts @config.to_yaml end end |
.config ⇒ Object
49 50 51 52 |
# File 'lib/solis/config_file.rb', line 49 def self.config init @config end |
.discover_config_file_path ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/solis/config_file.rb', line 69 def self.discover_config_file_path @config_file_path = ENV['CONFIG_FILE_PATH'] || '' if path.nil? || path.empty? if @config_file_path.nil? || @config_file_path.empty? if File.exist?(@config_file_name) @config_file_path = '.' elsif File.exist?("config/#{@config_file_name}") @config_file_path = 'config' end end @config_file_path = File.(@config_file_path) #puts "#{@config_file_name} found at #{@config_file_path}" end |
.include?(key) ⇒ Boolean
44 45 46 47 |
# File 'lib/solis/config_file.rb', line 44 def self.include?(key) init @config.include?(key) end |
.init ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/solis/config_file.rb', line 61 def self.init discover_config_file_path if @config.empty? config = YAML::load_file("#{path}/#{name}", aliases: true) @config = process(config) end end |
.keys ⇒ Object
54 55 56 57 |
# File 'lib/solis/config_file.rb', line 54 def self.keys init @config.keys end |
.name ⇒ Object
15 16 17 |
# File 'lib/solis/config_file.rb', line 15 def self.name @config_file_name end |
.name=(config_file_name) ⇒ Object
19 20 21 |
# File 'lib/solis/config_file.rb', line 19 def self.name=(config_file_name) @config_file_name = config_file_name end |
.path ⇒ Object
23 24 25 |
# File 'lib/solis/config_file.rb', line 23 def self.path @config_file_path end |
.path=(config_file_path) ⇒ Object
27 28 29 |
# File 'lib/solis/config_file.rb', line 27 def self.path=(config_file_path) @config_file_path = File.absolute_path(config_file_path) end |
.process(config) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/solis/config_file.rb', line 83 def self.process(config) new_config = {} config.each do |k,v| if config[k].is_a?(Hash) v = process(v) end # config.delete(k) new_config.store(k.to_sym, v) end new_config end |
.version ⇒ Object
11 12 13 |
# File 'lib/solis/config_file.rb', line 11 def self.version "0.0.4" end |