Class: Hygroscope::ParamSet
- Inherits:
-
Object
- Object
- Hygroscope::ParamSet
- Defined in:
- lib/hygroscope/paramset.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#parameters ⇒ Object
readonly
Returns the value of attribute parameters.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
- #get(key) ⇒ Object
-
#initialize(name = nil) ⇒ ParamSet
constructor
A new instance of ParamSet.
- #load! ⇒ Object
- #save! ⇒ Object
- #set(key, value, use_previous_value: false) ⇒ Object
Constructor Details
#initialize(name = nil) ⇒ ParamSet
Returns a new instance of ParamSet.
11 12 13 14 15 16 17 18 19 |
# File 'lib/hygroscope/paramset.rb', line 11 def initialize(name = nil) @parameters = {} @path = File.join(Dir.pwd, 'paramsets') return unless name @name = name load! end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
8 9 10 |
# File 'lib/hygroscope/paramset.rb', line 8 def name @name end |
#parameters ⇒ Object (readonly)
Returns the value of attribute parameters.
9 10 11 |
# File 'lib/hygroscope/paramset.rb', line 9 def parameters @parameters end |
#path ⇒ Object
Returns the value of attribute path.
8 9 10 |
# File 'lib/hygroscope/paramset.rb', line 8 def path @path end |
Instance Method Details
#get(key) ⇒ Object
38 39 40 |
# File 'lib/hygroscope/paramset.rb', line 38 def get(key) @parameters[key] end |
#load! ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/hygroscope/paramset.rb', line 21 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 |
#save! ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/hygroscope/paramset.rb', line 30 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 |
#set(key, value, use_previous_value: false) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/hygroscope/paramset.rb', line 42 def set(key, value, use_previous_value: false) @parameters[key] = if use_previous_value 'HYGROSCOPE_USE_PREVIOUS_VALUE' else value end end |