class Texico::ConfigFile

Constants

DEFAULT_CONFIG
DEFAULT_NAME
GLOBAL_CONFIG_PATH

Public Class Methods

new(config, defaults = {}) click to toggle source
# File lib/texico/config_file.rb, line 28
def initialize(config, defaults = {})
  @config = defaults.merge(config).freeze
end

Private Class Methods

default() click to toggle source
# File lib/texico/config_file.rb, line 41
def default
  return @default if @default
  @default = DEFAULT_CONFIG.merge read_global
end
exist?(opts) click to toggle source
# File lib/texico/config_file.rb, line 33
def exist?(opts)
  File.exist? opts[:config]
end
global() click to toggle source
# File lib/texico/config_file.rb, line 37
def global
  new read_global
end
load(opts, full = true) click to toggle source
# File lib/texico/config_file.rb, line 46
def load(opts, full = true)
  return false unless File.exist? opts[:config]
  new read_local(opts[:config]), (full ? default : {})
end
read_global() click to toggle source
# File lib/texico/config_file.rb, line 68
def read_global
  @global_defaults ||= read_local GLOBAL_CONFIG_PATH
end
read_local(filename) click to toggle source
# File lib/texico/config_file.rb, line 61
def read_local(filename)
  yaml = File.open(filename, 'rb') { |f| f.read }
  YAML.load(yaml) || {}
rescue Errno::ENOENT
  {}
end
store(config, dest = '', opts = {}) click to toggle source
# File lib/texico/config_file.rb, line 51
def store(config, dest = '', opts = {})
  return if opts[:dry_run]
  dest_path = File.expand_path opts[:config], dest
  File.open dest_path, 'wb' do |file|
    file.write YAML.dump(config.to_hash)
  end
end

Public Instance Methods

to_hash() click to toggle source
# File lib/texico/config_file.rb, line 22
def to_hash
  @config.dup
end