Class: Kiseru::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/ki_pivotal/kiseru.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root_path, app_name) ⇒ Config

Returns a new instance of Config.



38
39
40
41
42
43
44
45
46
47
# File 'lib/ki_pivotal/kiseru.rb', line 38

def initialize(root_path, app_name)
  @path = (root_path + "#{app_name}.yml").to_s
  unless File.exists?(@path)
    FileUtils.touch(@path)
    FileUtils.chmod(0600, @path)
  end
  @store = YAML::Store.new(@path)
  @store.transaction do
  end
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



32
33
34
# File 'lib/ki_pivotal/kiseru.rb', line 32

def path
  @path
end

Class Method Details

.[](key) ⇒ Object



34
35
36
# File 'lib/ki_pivotal/kiseru.rb', line 34

def self.[](key)
  ConfigDir.new.config(key)
end

Instance Method Details

#ensure_present(*keys) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/ki_pivotal/kiseru.rb', line 49

def ensure_present(*keys)
  keys.each do |key|
    if read(key).nil?
      raise ConfigError, "'#{key}' is not defined in config"
    end
  end
end

#read(key) ⇒ Object



63
64
65
66
67
# File 'lib/ki_pivotal/kiseru.rb', line 63

def read(key)
  @store.transaction(read_only=true) do
    @store[key]
  end
end

#write(key, value) ⇒ Object



57
58
59
60
61
# File 'lib/ki_pivotal/kiseru.rb', line 57

def write(key, value)
  @store.transaction do
    @store[key] = value
  end
end