Module: Confman

Defined in:
lib/confman.rb,
lib/confman/api.rb,
lib/confman/version.rb,
lib/confman/data_store.rb

Defined Under Namespace

Classes: API, Access, CLI, ConfFileNotFoundError, ConfSet, DataStore

Constant Summary collapse

VERSION =
"0.0.2"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.loggerObject



39
40
41
42
# File 'lib/confman.rb', line 39

def logger
  @logger ||= Logger.new(STDERR)
  @logger
end

Class Method Details

.accessObject



34
35
36
37
# File 'lib/confman.rb', line 34

def access
  @access ||= Confman::Access.new(api)
  @access
end

.apiObject



29
30
31
32
# File 'lib/confman.rb', line 29

def api
  @api ||= Confman::API.new
  @api
end

.load_conf_set(getter, conf_set_name) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/confman.rb', line 11

def load_conf_set(getter, conf_set_name)
  pairs = begin
    conf_set = Confman.api.find_by_name(conf_set_name)
    DataStore.write(getter, conf_set_name, conf_set.pairs.to_json)
    conf_set.pairs
  rescue => ex
    logger.error("load_conf_set(#{getter}, #{conf_set_name}): #{ex}")
    logger.error(ex.backtrace[0..5].join("\n"))
    d = DataStore.read(getter, conf_set_name)
    raise(ex) if d.nil? || d.blank?
    JSON.parse(d)
  end

  self.define_singleton_method(getter.to_s.to_sym) do
    OpenStruct.new(pairs)
  end
end