Class: ConfigRC::RcFileProvider

Inherits:
BaseProvider show all
Defined in:
lib/config-rc/rc_file.rb

Overview

Configuration stored in a file

Instance Method Summary collapse

Methods inherited from BaseProvider

#to_s

Constructor Details

#initialize(prefix) ⇒ RcFileProvider

Returns a new instance of RcFileProvider.



6
7
8
# File 'lib/config-rc/rc_file.rb', line 6

def initialize(prefix)
  @path = File.expand_path(File.join('~', ".#{prefix}rc"))
end

Instance Method Details

#mapObject



10
11
12
13
14
15
16
17
# File 'lib/config-rc/rc_file.rb', line 10

def map
  props = {}
  File.open(@path).select{|line| not line =~ /^[ \t]*(#.+)*$/}.each do |line|
    k, v = line.chomp.split('=', 2)
    props[k] = v
  end if File.exist?(@path)
  props
end