class Librarian::Config::FileSource

Attributes

config_path[RW]

Public Class Methods

new(adapter_name, options = { }) click to toggle source
Calls superclass method
# File lib/librarian/config/file_source.rb, line 12
def initialize(adapter_name, options = { })
  super

  self.config_path = options.delete(:config_path) or raise ArgumentError, "must provide config_path"
end

Public Instance Methods

to_s() click to toggle source
# File lib/librarian/config/file_source.rb, line 18
def to_s
  config_path
end

Private Instance Methods

load() click to toggle source
# File lib/librarian/config/file_source.rb, line 24
def load
  return { } unless File.file?(config_path)

  raw = YAML.load_file(config_path)
  return { } unless Hash === raw

  translate_raw_to_config(raw)
end
save(config) click to toggle source
# File lib/librarian/config/file_source.rb, line 33
def save(config)
  raw = translate_config_to_raw(config)

  if config.empty?
    File.delete(config_path) if File.file?(config_path)
  else
    config_dir = File.dirname(config_path)
    FileUtils.mkpath(config_dir) unless File.directory?(config_dir)
    File.open(config_path, "wb"){|f| YAML.dump(raw, f)}
  end
end