Class: Kafo::Store

Inherits:
Object
  • Object
show all
Defined in:
lib/kafo/store.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = nil) ⇒ Store

Returns a new instance of Store.



7
8
9
10
# File 'lib/kafo/store.rb', line 7

def initialize(path = nil)
  @data = {}
  load_path(path) if path
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



5
6
7
# File 'lib/kafo/store.rb', line 5

def data
  @data
end

Instance Method Details

#add(data) ⇒ Object



20
21
22
# File 'lib/kafo/store.rb', line 20

def add(data)
  @data.merge!(data)
end

#add_dir(path) ⇒ Object



24
25
26
27
28
# File 'lib/kafo/store.rb', line 24

def add_dir(path)
  Dir.glob(File.join(path, "*.yaml")).sort.each do |file|
    add_file(file)
  end
end

#add_file(file) ⇒ Object



30
31
32
# File 'lib/kafo/store.rb', line 30

def add_file(file)
  add(YAML.load_file(file))
end

#get(key) ⇒ Object



34
35
36
# File 'lib/kafo/store.rb', line 34

def get(key)
  @data[key]
end

#load_path(path) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/kafo/store.rb', line 12

def load_path(path)
  if File.directory?(path)
    add_dir(path)
  else
    add_file(path)
  end
end