Class: Outil::OCS::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/outil/ocs/config.rb

Constant Summary collapse

INDEX_PATH =
'.outil'
CONFIG_PATH =
'.outil.rc'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Config

Returns a new instance of Config.



15
16
17
18
19
20
21
22
# File 'lib/outil/ocs/config.rb', line 15

def initialize(params={})
  @params = params
  infer = Proc.new do |key, const|
    @params[key] = "#{self.class.home_path}/#{const}"
  end
  infer.call(:index, INDEX_PATH)
  infer.call(:path, CONFIG_PATH)
end

Instance Attribute Details

#paramsObject (readonly)

Returns the value of attribute params.



13
14
15
# File 'lib/outil/ocs/config.rb', line 13

def params
  @params
end

Class Method Details

.home_pathObject



8
9
10
11
# File 'lib/outil/ocs/config.rb', line 8

def self.home_path
  @home_path ||= File.expand_path(
    File.expand_path(ENV['HOME'] || '~'))
end

Instance Method Details

#indexObject



39
40
41
42
43
44
45
46
# File 'lib/outil/ocs/config.rb', line 39

def index
  @index ||= (
    unless options[:index]
      raise StandardError "Could not locate your Outil Index Path"
    end
    Index.new(:path => options[:index])
  )
end

#optionsObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/outil/ocs/config.rb', line 24

def options
  @options ||= (
    unless File.exists?(@params[:path])
      raise StandardError "Could not locate your Outil Config File"
    end
    indifference = Proc.new do |hash, x|
      hash[x.first] = x.last
      hash[x.first.to_sym] = x.last
      hash
    end
    YAML.load_file(@params[:path])
      .inject(Hash.new, &indifference)
    )
end