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) ⇒ 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') if name @name = name self.load! end 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
39 40 41 |
# File 'lib/hygroscope/paramset.rb', line 39 def get(key) @parameters[key] end |
#load! ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/hygroscope/paramset.rb', line 21 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 |
#save! ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/hygroscope/paramset.rb', line 31 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) ⇒ Object
43 44 45 |
# File 'lib/hygroscope/paramset.rb', line 43 def set(key, value) @parameters[key] = value end |