class Zashoku::Config
Constants
- CONF_DIR
- CONF_FILE
Public Class Methods
new()
click to toggle source
# File lib/core/config/config.rb, line 11 def initialize FileUtils.mkdir_p(CONF_DIR) if save? && !File.directory?(CONF_DIR) reload save unless File.exist?(self.class::CONF_FILE) end
Public Instance Methods
base_conf()
click to toggle source
# File lib/core/config/config.rb, line 26 def base_conf {} end
default_conf()
click to toggle source
# File lib/core/config/config.rb, line 30 def default_conf module_conf.reduce(base_conf) do |mem, mc| Zashoku::Util.deep_merge(mem, mc) end end
get(trail)
click to toggle source
# File lib/core/config/config.rb, line 84 def get(trail) @conf.dig(*trail) end
items(c = @conf, pre = '', path = [])
click to toggle source
# File lib/core/config/config.rb, line 48 def items(c = @conf, pre = '', path = []) return pref_model(pre, c, path) unless c.respond_to?(:map) c.map do |title, pref| # next if IGNORE.key? title t = "#{pre}_#{title}" pth = path + [title] case pref when Hash pref.map do |subt, subpref| items(subpref, "#{pre}_#{title}_#{subt}", [title, subt]) #pref_model("#{title}_#{subt}", subpref, [title, subt]) end when Array pref_model(t, pref.join(':'), pth) else pref_model(t, pref, pth) end end.flatten #.compact end
module_conf()
click to toggle source
# File lib/core/config/config.rb, line 36 def module_conf {} end
parse_dir(path)
click to toggle source
# File lib/core/config/config.rb, line 68 def parse_dir(path) { '$conf_dir' => CONF_DIR, '~' => Dir.home }.inject(path) { |p, r| p.gsub(r[0], r[1]) } end
pref_model(title, value, trail)
click to toggle source
# File lib/core/config/config.rb, line 44 def pref_model(title, value, trail) Item.new('title' => title, 'value' => value, 'trail' => trail) end
reload()
click to toggle source
# File lib/core/config/config.rb, line 21 def reload @conf = Zashoku::Util.deep_merge(default_conf, user_conf) save end
save()
click to toggle source
# File lib/core/config/config.rb, line 88 def save return unless save? File.open(self.class::CONF_FILE, 'w') { |f| f.write(YAML.dump(@conf)) } end
save?()
click to toggle source
# File lib/core/config/config.rb, line 17 def save? Zashoku::CConf[:app][:save_config] end
set(trail, destination)
click to toggle source
# File lib/core/config/config.rb, line 75 def set(trail, destination) trail = [trail] if trail.class == String trail[0...-1].inject(@conf, :fetch)[trail.last] = destination save changed notify_observers end
user_conf()
click to toggle source
# File lib/core/config/config.rb, line 40 def user_conf Util.get_yaml(self.class::CONF_FILE) end