Class: Ixtlan::Passwords

Inherits:
Object
  • Object
show all
Defined in:
lib/ixtlan/passwords.rb

Class Method Summary collapse

Class Method Details

.[](key) ⇒ Object



60
61
62
# File 'lib/ixtlan/passwords.rb', line 60

def self.[]( key )
  @config[ key ]
end

.config(file = 'password.yml') ⇒ Object



56
57
58
# File 'lib/ixtlan/passwords.rb', line 56

def self.config( file = 'password.yml' )
  @config ||= load( file ) || HashWithDefault.new
end

.get(key, default = nil) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/ixtlan/passwords.rb', line 64

def self.get( key, default = nil )
  if default
    @config.get( key, default )
  else
    @config.get( key )
  end
end

.load(file) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/ixtlan/passwords.rb', line 46

def self.load( file )
  rel_file = File.expand_path( file ).sub( /#{File.expand_path '.' }\/?/, '' )
  if File.exists?( file )
    warn "[Passwords] Loaded #{rel_file} file"
    symbolize_keys( YAML::load( ERB.new( IO.read( file ) ).result ) )
  else
    warn "[Passwords] No #{rel_file} file to load"
  end
end

.symbolize_keys(h) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ixtlan/passwords.rb', line 32

def self.symbolize_keys(h)
  result = HashWithDefault.new

  h.each do |k, v|
    v = ' ' if v.nil?
    if v.is_a?(Hash)
      result[k.to_sym] = symbolize_keys(v) unless v.size == 0
    else
      result[k.to_sym] = v unless k.to_sym == v.to_sym
    end
  end
  result
end