Class: Flow::Cli::Utils::DbManager

Inherits:
Object
  • Object
show all
Defined in:
lib/flow/cli/utils/db_manager.rb

Constant Summary collapse

FLOW_CLI_CONFIG =
"#{ENV['HOME']}/.flow_cli_config.yml".freeze

Class Method Summary collapse

Class Method Details

.overide_save(hash) ⇒ Object



9
10
11
12
13
14
# File 'lib/flow/cli/utils/db_manager.rb', line 9

def overide_save(hash)
  File.open(FLOW_CLI_CONFIG, "w") do |file|
    file << hash.to_yaml
  end
  hash
end

.readObject



36
37
38
39
40
41
# File 'lib/flow/cli/utils/db_manager.rb', line 36

def read
  return {} unless File.file?(FLOW_CLI_CONFIG)
  config = YAML.safe_load(File.read(FLOW_CLI_CONFIG))
  raise "yaml load is not a hash #{config.class}" unless config.is_a? Hash
  config
end

.read_attribute(key) ⇒ Object



43
44
45
# File 'lib/flow/cli/utils/db_manager.rb', line 43

def read_attribute(key)
  read[key.to_s]
end

.resetObject



16
17
18
# File 'lib/flow/cli/utils/db_manager.rb', line 16

def reset
  overide_save({})
end

.save(settings) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/flow/cli/utils/db_manager.rb', line 20

def save(settings)
  old = read
  settings = old.merge(settings).compact.stringify_keys
  yaml = settings.to_yaml
  File.open(FLOW_CLI_CONFIG, "w") do |file|
    file << yaml
  end
  settings
end

.save_attribute(key, val) ⇒ Object



30
31
32
33
34
# File 'lib/flow/cli/utils/db_manager.rb', line 30

def save_attribute(key, val)
  dict = read
  dict[key.to_s] = val
  save(dict)
end