Module: Labrat::LabelDb

Defined in:
lib/labrat/label_db.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.dbObject

Module-level variable to hold the merged database.



7
8
9
# File 'lib/labrat/label_db.rb', line 7

def db
  @db
end

.readerObject

Module-level variable to hold the merged database.



7
8
9
# File 'lib/labrat/label_db.rb', line 7

def reader
  @reader
end

Class Method Details

.[](labname) ⇒ Object

Return a hash of config settings for the label named by labname.



18
19
20
21
# File 'lib/labrat/label_db.rb', line 18

def self.[](labname)
  read unless db
  db[labname.to_sym] || db[labname.downcase.to_sym] || {}
end

.[]=(labname, config = {}) ⇒ Object

Set a runtime configuration for a single labelname.



24
25
26
27
# File 'lib/labrat/label_db.rb', line 24

def self.[]=(labname, config = {})
  read unless db
  db[labname.to_sym.downcase] = config
end

.db_paths(dir_prefix = '') ⇒ Object



35
36
37
# File 'lib/labrat/label_db.rb', line 35

def self.db_paths(dir_prefix = '')
  system_db_paths(dir_prefix) + user_db_paths(dir_prefix)
end

.known_namesObject

Return an Array of label names.



30
31
32
33
# File 'lib/labrat/label_db.rb', line 30

def self.known_names
  read unless db
  db.keys.sort
end

.read(dir_prefix: '') ⇒ Object

Read in the Labrat database of label settings, merging system and user databases.



12
13
14
15
# File 'lib/labrat/label_db.rb', line 12

def self.read(dir_prefix: '')
  self.reader = FatConfig::Reader.new('labrat', root_prefix: dir_prefix)
  self.db = reader.read('labeldb').transform_keys(&:downcase)
end

.system_db_paths(dir_prefix = '') ⇒ Object



39
40
41
# File 'lib/labrat/label_db.rb', line 39

def self.system_db_paths(dir_prefix = '')
  reader.config_paths[:system]
end

.user_db_paths(dir_prefix = '') ⇒ Object



43
44
45
# File 'lib/labrat/label_db.rb', line 43

def self.user_db_paths(dir_prefix = '')
  reader.config_paths[:user]
end