Class: Solis::ConfigFile

Inherits:
Object
  • Object
show all
Defined in:
lib/solis/config_file.rb

Class Method Summary collapse

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

.configObject



49
50
51
52
# File 'lib/solis/config_file.rb', line 49

def self.config
  init
  @config
end

.discover_config_file_pathObject



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.expand_path(@config_file_path)
  #puts "#{@config_file_name} found at #{@config_file_path}"
end

.include?(key) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
47
# File 'lib/solis/config_file.rb', line 44

def self.include?(key)
  init
  @config.include?(key)
end

.initObject



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

.keysObject



54
55
56
57
# File 'lib/solis/config_file.rb', line 54

def self.keys
  init
  @config.keys
end

.nameObject



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

.pathObject



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

.versionObject



11
12
13
# File 'lib/solis/config_file.rb', line 11

def self.version
  "0.0.4"
end