Class: CodeUnion::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/codeunion/config.rb

Overview

Manages CodeUnion configuration data

Defined Under Namespace

Classes: FileAdapter

Constant Summary collapse

DEFAULT_CONFIG_FILE =
File.join(Dir.home, ".codeunion", "config")

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_file) ⇒ Config

Returns a new instance of Config.



12
13
14
15
16
# File 'lib/codeunion/config.rb', line 12

def initialize(config_file)
  @file = config_file
  @config = Hash.try_convert(config_file)
  @config.default_proc = proc { |h, k| h[k] = {} }
end

Class Method Details

.load(config_file_path = DEFAULT_CONFIG_FILE) ⇒ Object



8
9
10
# File 'lib/codeunion/config.rb', line 8

def self.load(config_file_path = DEFAULT_CONFIG_FILE)
  CodeUnion::Config.new(FileAdapter.new(config_file_path))
end

Instance Method Details

#get(dotted_key) ⇒ Object



28
29
30
# File 'lib/codeunion/config.rb', line 28

def get(dotted_key)
  get_dotted(@config, dotted_key)
end

#set(dotted_key, value) ⇒ Object



18
19
20
21
# File 'lib/codeunion/config.rb', line 18

def set(dotted_key, value)
  @config = set_dotted(@config, dotted_key, value)
  self
end

#to_hashObject Also known as: to_h



32
33
34
# File 'lib/codeunion/config.rb', line 32

def to_hash
  @config.dup
end

#unset(dotted_key) ⇒ Object



23
24
25
26
# File 'lib/codeunion/config.rb', line 23

def unset(dotted_key)
  @config = unset_dotted(@config, dotted_key)
  self
end

#writeObject



38
39
40
# File 'lib/codeunion/config.rb', line 38

def write
  @file.write(to_hash)
end