Class: Completely::Config

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ Config

Returns a new instance of Config.



16
17
18
19
# File 'lib/completely/config.rb', line 16

def initialize(config)
  @options = config.delete('completely_options')&.transform_keys(&:to_sym) || {}
  @config = config
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



3
4
5
# File 'lib/completely/config.rb', line 3

def config
  @config
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/completely/config.rb', line 3

def options
  @options
end

Class Method Details

.load(path) ⇒ Object



12
# File 'lib/completely/config.rb', line 12

def load(path) = parse(File.read(path))

.parse(str) ⇒ Object



6
7
8
9
10
# File 'lib/completely/config.rb', line 6

def parse(str)
  new YAML.load(str, aliases: true)
rescue Psych::Exception => e
  raise ParseError, "Invalid YAML: #{e.message}"
end

.read(io) ⇒ Object



13
# File 'lib/completely/config.rb', line 13

def read(io) = parse(io.read)

Instance Method Details

#flat_configObject



21
22
23
24
25
26
27
28
29
# File 'lib/completely/config.rb', line 21

def flat_config
  result = {}

  config.each do |root_key, root_list|
    result.merge! process_key(root_key, root_list)
  end

  result
end