Class: Expd::Config
- Inherits:
-
Object
- Object
- Expd::Config
- Extended by:
- Forwardable
- Defined in:
- lib/expd/config.rb
Class Method Summary collapse
-
.defaults ⇒ Object
Return a configuration loaded from the default config file.
Instance Method Summary collapse
-
#initialize(filename) ⇒ Config
constructor
A new instance of Config.
-
#load_from_file! ⇒ Object
Load the configuration from its file if it exists.
-
#save! ⇒ Object
Save the configuration on disk.
-
#snippets ⇒ Object
Shortcut to get the snippets.
Constructor Details
#initialize(filename) ⇒ Config
Returns a new instance of Config.
10 11 12 13 14 |
# File 'lib/expd/config.rb', line 10 def initialize(filename) @filename = filename @conf = {} load_from_file! end |
Class Method Details
.defaults ⇒ Object
Return a configuration loaded from the default config file
34 35 36 |
# File 'lib/expd/config.rb', line 34 def self.defaults new File.("~/.expd_snippets") end |
Instance Method Details
#load_from_file! ⇒ Object
Load the configuration from its file if it exists. This already performed on instance creation.
18 19 20 21 |
# File 'lib/expd/config.rb', line 18 def load_from_file! @conf = YAML.load_file @filename if File.exist?(@filename) @conf[:snippets] ||= {} end |
#save! ⇒ Object
Save the configuration on disk
24 25 26 |
# File 'lib/expd/config.rb', line 24 def save! File.open(@filename, "w") { |f| f.write YAML.dump(@conf) } end |
#snippets ⇒ Object
Shortcut to get the snippets
29 30 31 |
# File 'lib/expd/config.rb', line 29 def snippets self[:snippets] end |