Class: Metastore::Cabinet

Inherits:
Object
  • Object
show all
Defined in:
lib/metastore/cabinet.rb

Instance Method Summary collapse

Constructor Details

#initialize(file, storage_type: :yaml) ⇒ Cabinet

Returns a new instance of Cabinet.



7
8
9
10
# File 'lib/metastore/cabinet.rb', line 7

def initialize(file, storage_type: :yaml)
  @file = Pathname.new(file).expand_path
  @storage_type = storage_type
end

Instance Method Details

#clear!Object



22
23
24
# File 'lib/metastore/cabinet.rb', line 22

def clear!
  save!({})
end

#contentsObject



26
27
28
# File 'lib/metastore/cabinet.rb', line 26

def contents
  storage.contents || {}
end

#get(key) ⇒ Object Also known as: []



12
13
14
# File 'lib/metastore/cabinet.rb', line 12

def get(key)
  split_key(key).inject(contents) { |c, k| c.is_a?(Hash) ? c[k] : nil }
end

#set(key, value) ⇒ Object Also known as: []=



16
17
18
19
20
# File 'lib/metastore/cabinet.rb', line 16

def set(key, value)
  current_contents = contents
  set_key_and_value(current_contents, split_key(key), value)
  save!(current_contents)
end