Class: GeneValidatorApp::Config

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/genevalidatorapp/config.rb

Overview

Capture our configuration system.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = {}) ⇒ Config

Returns a new instance of Config.



11
12
13
14
15
16
17
# File 'lib/genevalidatorapp/config.rb', line 11

def initialize(data = {})
  @data = symbolise data
  @config_file = @data.delete(:config_file) || default_config_file
  @config_file = File.expand_path(@config_file)
  @data = parse_config_file.update @data
  @data = defaults.update @data
end

Instance Attribute Details

#config_fileObject (readonly)

Returns the value of attribute config_file.



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

def config_file
  @config_file
end

#dataObject (readonly)

Returns the value of attribute data.



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

def data
  @data
end

Instance Method Details

#[](key) ⇒ Object

Get.



22
23
24
# File 'lib/genevalidatorapp/config.rb', line 22

def [](key)
  data[key]
end

#[]=(key, value) ⇒ Object

Set.



27
28
29
# File 'lib/genevalidatorapp/config.rb', line 27

def []=(key, value)
  data[key] = value
end

#include?(key) ⇒ Boolean

Exists?

Returns:

  • (Boolean)


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

def include?(key)
  data.include? key
end

#write_config_fileObject

Write config data to config file.



37
38
39
40
41
42
43
# File 'lib/genevalidatorapp/config.rb', line 37

def write_config_file
  return unless config_file

  File.open(config_file, 'w') do |f|
    f.puts(data.delete_if { |_, v| v.nil? }.to_yaml)
  end
end