Sha256: a3c491ec604b6cd207464a257579b1d8f4204158d649fa748591eaddb25a2ccf

Contents?: true

Size: 1.01 KB

Versions: 8

Compression:

Stored size: 1.01 KB

Contents

require 'yaml'
module Kymera
  class Config

    #The constructor reads in the config.yaml file, converts it into a hash and then defines methods on this class based on the
    #different sections
    def initialize
      yaml_file = File.open(File.join(Dir.pwd, '/kymera_config.yaml'), 'r+')
      yaml_file.rewind
      @config_options = YAML.load(yaml_file.read)
      @config_options.each do |key, value|
        define_singleton_method(key){value}
      end
      yaml_file.close
    end

    #This takes any changes that were made to the different sections and updates the config.yaml file (more to the point, overrides the old file
    # and replaces the entire file with the new values)
    def update
      yaml_file = File.open(File.join(Dir.pwd, '/kymera_config.yaml'), 'w+')
      @config_options.to_yaml.split('\n').each do |line|
        yaml_file.write(line)
      end
      yaml_file.rewind
      str = yaml_file.read
      yaml_file.close
      str
    end

    def to_s
      @config_options.to_yaml
    end


  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
kymera-0.1.7 lib/kymera/config/config.rb
kymera-0.1.6 lib/kymera/config/config.rb
kymera-0.1.5 lib/kymera/config/config.rb
kymera-0.1.4 lib/kymera/config/config.rb
kymera-0.1.3 lib/kymera/config/config.rb
kymera-0.1.2 lib/kymera/config/config.rb
kymera-0.1.1 lib/kymera/config/config.rb
kymera-0.1.0 lib/kymera/config/config.rb