class Caravan::Config
Constants
- DEFAULT_CONFIG
- DEFAULT_CONFIG_NAME
- DEFAULT_SPEC_NAME
Public Class Methods
default_conf()
click to toggle source
# File lib/caravan/config.rb, line 21 def default_conf DEFAULT_CONFIG.dup end
default_conf_name()
click to toggle source
# File lib/caravan/config.rb, line 25 def default_conf_name DEFAULT_CONFIG_NAME end
default_spec_name()
click to toggle source
# File lib/caravan/config.rb, line 29 def default_spec_name DEFAULT_SPEC_NAME end
dump(user_config_path, user_config)
click to toggle source
# File lib/caravan/config.rb, line 43 def dump(user_config_path, user_config) # rubocop:disable Metrics/LineLength File.open(user_config_path, "w") do |f| f.write("# Generated Caravan's configuration file.\n") f.write("# Use `caravan --help` for instructions on all the configuration values.\n") f.write("# Add `src` and `dst` to specify the source and destination.\n") f.write(user_config.to_yaml) end # rubocop:enable Metrics/LineLength end
from(user_config_path)
click to toggle source
# File lib/caravan/config.rb, line 33 def from(user_config_path) if File.exist?(user_config_path) YAML.load_file(user_config_path) else Caravan::Message.warn("User configuration [caravan.yml] not found.") Caravan::Message.warn("Use `caravan --init` to generate.") nil end end
merge(options, conf, spec = Caravan::Config.default_spec_name)
click to toggle source
# File lib/caravan/config.rb, line 54 def merge(options, conf, spec = Caravan::Config.default_spec_name) merged_conf = if conf.nil? Caravan::Message.warn("Fail to load conf. Use default instead.") default_spec_name = Caravan::Config.default_spec_name Caravan::Config.default_conf[default_spec_name] else stringify_keys(conf)[spec] end merged_conf["src"] = options[:src] if options.key?(:src) merged_conf["dst"] = options[:dst] if options.key?(:dst) merged_conf["debug"] = options[:debug] if options.key?(:debug) merged_conf["deploy_mode"] = options[:mode] if options.key?(:mode) merged_conf["exclude"] = options[:ignore] if options.key?(:ignore) merged_conf["once"] = options[:once] if options.key?(:once) merged_conf end
pretty_puts(conf)
click to toggle source
# File lib/caravan/config.rb, line 73 def pretty_puts(conf) conf.each do |k, v| Caravan::Message.info("=> #{k}: #{v}") end end
Private Class Methods
stringify_keys(conf)
click to toggle source
# File lib/caravan/config.rb, line 81 def stringify_keys(conf) new_conf = {} conf.each do |sym, v| new_conf[sym.to_s] = v end new_conf end