Class: SequenceServer::Config

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/sequenceserver/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


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

def initialize(data = {})
  @data = normalize 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


20
21
22
# File 'lib/sequenceserver/config.rb', line 20

def config_file
  @config_file
end

#dataObject (readonly)

Returns the value of attribute data


20
21
22
# File 'lib/sequenceserver/config.rb', line 20

def data
  @data
end

Instance Method Details

#[](key) ⇒ Object

Get.


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

def [](key)
  data[key]
end

#[]=(key, value) ⇒ Object

Set.


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

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

#include?(key) ⇒ Boolean

Exists?

Returns:

  • (Boolean)

33
34
35
# File 'lib/sequenceserver/config.rb', line 33

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

#write_config_fileObject

Write config data to config file.


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

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