Sha256: 0bdd4ce277890d9d39330f31efdf1e614b274c4cd2fbeaf527e123c15c475497

Contents?: true

Size: 936 Bytes

Versions: 10

Compression:

Stored size: 936 Bytes

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')

      if name
        @name = name
        self.load!
      end
    end

    def load!
      files = Dir.glob(File.join(@path, @name + '.{yml,yaml}'))
      if files.empty?
        fail Hygroscope::ParamSetNotFoundError
      else
        @file = files.first
        @parameters = YAML.load_file(@file)
      end
    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)
      @parameters[key] = value
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
hygroscope-1.2.0 lib/hygroscope/paramset.rb
hygroscope-1.1.7 lib/hygroscope/paramset.rb
hygroscope-1.1.6 lib/hygroscope/paramset.rb
hygroscope-1.1.5 lib/hygroscope/paramset.rb
hygroscope-1.1.4 lib/hygroscope/paramset.rb
hygroscope-1.1.3 lib/hygroscope/paramset.rb
hygroscope-1.1.2 lib/hygroscope/paramset.rb
hygroscope-1.1.1 lib/hygroscope/paramset.rb
hygroscope-1.1.0 lib/hygroscope/paramset.rb
hygroscope-1.0.0 lib/hygroscope/paramset.rb