Sha256: 8f4d895ccd8915b4cb06cb51422b38d03e2d0a1fa34bd723285b27be62cfd4be
Contents?: true
Size: 1.07 KB
Versions: 3
Compression:
Stored size: 1.07 KB
Contents
require 'hygroscope' module Hygroscope class ParamSetNotFoundError < StandardError end class ParamSet attr_accessor :name, :path attr_reader :parameters def initialize(name = nil) @parameters = {} @path = File.join(Dir.pwd, 'paramsets') return unless name @name = name load! end def load! files = Dir.glob(File.join(@path, @name + '.{yml,yaml}')) raise Hygroscope::ParamSetNotFoundError if files.empty? @file = files.first @parameters = YAML.load_file(@file) end def save! # If this is a new paramset, construct a filename savefile = @file || File.join(@path, @name + '.yaml') File.open(savefile, 'w') do |f| YAML.dump(@parameters, f) end end def get(key) @parameters[key] end def set(key, value, use_previous_value: false) @parameters[key] = if use_previous_value 'HYGROSCOPE_USE_PREVIOUS_VALUE' else value end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
hygroscope-1.3.2 | lib/hygroscope/paramset.rb |
hygroscope-1.3.1 | lib/hygroscope/paramset.rb |
hygroscope-1.3.0 | lib/hygroscope/paramset.rb |