Class: Ezframe::Config

Inherits:
Object show all
Defined in:
lib/ezframe/config.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.value_hObject

Returns the value of attribute value_h.



4
5
6
# File 'lib/ezframe/config.rb', line 4

def value_h
  @value_h
end

Class Method Details

.[](k) ⇒ Object



42
43
44
# File 'lib/ezframe/config.rb', line 42

def [](k)
  @value_h[k] if @value_h
end

.[]=(k, v) ⇒ Object



46
47
48
49
# File 'lib/ezframe/config.rb', line 46

def []=(k, v)
  @value_h||={}
  @value_h[k]=v
end

.delete(k) ⇒ Object



51
52
53
# File 'lib/ezframe/config.rb', line 51

def delete(k)
  @value_h.delete(k) if @value_h[k]
end

.init(dir = "./config") ⇒ Object



6
7
8
# File 'lib/ezframe/config.rb', line 6

def init(dir = "./config")
  load_files(dir)
end

.inspectObject



55
56
57
# File 'lib/ezframe/config.rb', line 55

def inspect
  @value_h.inspect
end

.load_dir(dir) ⇒ Object



21
22
23
24
25
# File 'lib/ezframe/config.rb', line 21

def load_dir(dir)
  Dir["#{dir}/*.yml"].each do |file|
    load_one_file(file)
  end
end

.load_files(dir) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/ezframe/config.rb', line 10

def load_files(dir)
  unless @value_h
    load_dir(dir)
    rack_env = ENV['RACK_ENV']
    env_dir = "#{dir}/#{rack_env}"
    if rack_env && File.directory?(env_dir)
      load_dir(env_dir)
    end
  end
end

.load_one_file(filename) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ezframe/config.rb', line 27

def load_one_file(filename)
  instr = File.open(filename, &:read)
  if instr.index("\#{")
    instr = Template.fill_in_text(instr)
  end
  begin
    yaml = YAML.load(instr, symbolize_names: true)
  rescue => e
    EzLog.info("YAML load error: #{filename}:#{e}")
    return 
  end
  @value_h ||={}
  @value_h.update(yaml) if yaml.length>0 # .recursively_symbolize_keys
end