Class: Thot::Varfiles

Inherits:
Object
  • Object
show all
Extended by:
Carioca::Injector
Defined in:
lib/thot/varfiles.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(varfile: nil, environment: nil, dotfiles: ["./.thot.env","~/.thot.env"]) ⇒ Varfiles

Returns a new instance of Varfiles.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/thot/varfiles.rb', line 8

def initialize(varfile: nil, environment: nil, dotfiles: ["./.thot.env","~/.thot.env"])
    @name = self.class
    @data = {}
    scanned_files = dotfiles
    scanned_files.push varfile unless varfile.nil?
    scanned_files.each do |file|
        real_file = File.expand_path(file)
        if File::exists? real_file then
            output.debug "Negociated files : #{real_file}, merging..." if self.respond_to?(:output)
            datafile = IniFile.load(real_file)
            @data.merge! datafile["global"]
            @data.merge! datafile[environment] if datafile.sections.include? environment.to_s
        end
    end
    @data.transform_keys!(&:to_sym)
    if self.respond_to?(:output) then
        if output.level == :debug then 
            output.debug "merged data:"
            @data.each  do |key,val|
                output.debug "* #{key} = #{val}"
            end
        end
    end
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



5
6
7
# File 'lib/thot/varfiles.rb', line 5

def data
  @data
end