Class: Texico::ConfigFile
- Inherits:
-
Object
- Object
- Texico::ConfigFile
- Extended by:
- Forwardable
- Defined in:
- lib/texico/config_file.rb
Constant Summary collapse
- DEFAULT_NAME =
'.texico'.freeze
- GLOBAL_CONFIG_PATH =
File.(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
- .default ⇒ Object
- .exist?(opts) ⇒ Boolean
- .global ⇒ Object
- .load(opts, full = true) ⇒ Object
- .store(config, dest = '', opts = {}) ⇒ Object
Instance Method Summary collapse
Class Method Details
.default ⇒ Object
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
33 34 35 |
# File 'lib/texico/config_file.rb', line 33 def exist?(opts) File.exist? opts[:config] end |
.global ⇒ Object
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. opts[:config], dest File.open dest_path, 'wb' do |file| file.write YAML.dump(config.to_hash) end end |
Instance Method Details
#to_hash ⇒ Object
22 23 24 |
# File 'lib/texico/config_file.rb', line 22 def to_hash @config.dup end |