Class: Unipept::Configuration
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#file_name ⇒ Object
readonly
Returns the value of attribute file_name.
Instance Method Summary collapse
-
#[](*args) ⇒ Object
forwards [] to the internal config hash.
-
#[]=(*args) ⇒ Object
forwards =[] to the internal config hash.
-
#delete(key) ⇒ Object
Deletes a key.
-
#initialize(file = nil) ⇒ Configuration
constructor
Creates a new config object, based on a given YAML file.
-
#save ⇒ Object
Saves the config to disk.
Constructor Details
#initialize(file = nil) ⇒ Configuration
Creates a new config object, based on a given YAML file. If no filename given, ‘.unipeptrc’ in the home dir of the user will be used.
If the file doesn’t exist, an empty config will be loaded.
config from
14 15 16 17 18 19 20 21 |
# File 'lib/configuration.rb', line 14 def initialize(file = nil) @file_name = file || File.join(Dir.home, '.unipeptrc') @config = if File.exist? file_name YAML.load_file file_name, permitted_classes: [Time] else {} end end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
5 6 7 |
# File 'lib/configuration.rb', line 5 def config @config end |
#file_name ⇒ Object (readonly)
Returns the value of attribute file_name.
5 6 7 |
# File 'lib/configuration.rb', line 5 def file_name @file_name end |
Instance Method Details
#[](*args) ⇒ Object
forwards [] to the internal config hash
35 36 37 |
# File 'lib/configuration.rb', line 35 def [](*args) config.[](*args) end |
#[]=(*args) ⇒ Object
forwards =[] to the internal config hash
40 41 42 |
# File 'lib/configuration.rb', line 40 def []=(*args) config.[]=(*args) # rubocop:disable Layout/SpaceBeforeBrackets end |
#delete(key) ⇒ Object
Deletes a key
30 31 32 |
# File 'lib/configuration.rb', line 30 def delete(key) config.delete(key) end |
#save ⇒ Object
Saves the config to disk. If the file doesn’t exist yet, a new one will be created
25 26 27 |
# File 'lib/configuration.rb', line 25 def save File.write(file_name, config.to_yaml) end |