Class: Texico::ConfigFile

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/texico/config_file.rb

Constant Summary collapse

DEFAULT_NAME =
'.texico'.freeze
GLOBAL_CONFIG_PATH =
File.expand_path(DEFAULT_NAME, ENV['HOME']).freeze
DEFAULT_CONFIG =
{
  name: 'main',
  title: 'Title',
  author: 'Author',
  email: '[email protected]',
  build: 'build',
  main_file: 'main.tex'
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.defaultObject



41
42
43
44
# File 'lib/texico/config_file.rb', line 41

def default
  return @default if @default
  @default = DEFAULT_CONFIG.merge read_global
end

.exist?(opts) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/texico/config_file.rb', line 33

def exist?(opts)
  File.exist? opts[:config]
end

.globalObject



37
38
39
# File 'lib/texico/config_file.rb', line 37

def global
  new read_global
end

.load(opts, full = true) ⇒ Object



46
47
48
49
# 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

.store(config, dest = '', opts = {}) ⇒ Object



51
52
53
54
55
56
57
# 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

Instance Method Details

#to_hashObject



22
23
24
# File 'lib/texico/config_file.rb', line 22

def to_hash
  @config.dup
end