Class: Tagmv::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/tagmv/config.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Config

Returns a new instance of Config.



5
6
7
# File 'lib/tagmv/config.rb', line 5

def initialize(options = {})
  @path = options[:path] || File.expand_path("~/.tagmv.yml")
end

Instance Method Details

#defaultsObject



9
10
11
# File 'lib/tagmv/config.rb', line 9

def defaults
  {top_level_tags: ["blog", "media"]}
end

#loadObject



13
14
15
16
17
18
19
20
21
# File 'lib/tagmv/config.rb', line 13

def load
  if File.file?(@path)
    YAML.load(File.open(@path).read)
  else
    config = defaults
    save(config)
    config
  end
end

#save(config) ⇒ Object



23
24
25
# File 'lib/tagmv/config.rb', line 23

def save(config)
  File.open(@path, 'w') { |f| f.write(config.to_yaml) }
end