Class: Expd::Config

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/expd/config.rb

Class Method Summary collapse

Instance Method Summary collapse

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

.defaultsObject

Return a configuration loaded from the default config file



34
35
36
# File 'lib/expd/config.rb', line 34

def self.defaults
  new File.expand_path("~/.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

#snippetsObject

Shortcut to get the snippets



29
30
31
# File 'lib/expd/config.rb', line 29

def snippets
  self[:snippets]
end