Class: Caravan::Config
- Inherits:
-
Hash
- Object
- Hash
- Caravan::Config
- Defined in:
- lib/caravan/config.rb
Constant Summary collapse
- DEFAULT_CONFIG =
{ "master" => { "debug" => false, "deploy_mode" => "rsync", "incremental" => true, "exclude" => %w( .git .svn ), "once" => false } }.freeze
- DEFAULT_CONFIG_NAME =
"caravan.yml".freeze
- DEFAULT_SPEC_NAME =
"master".freeze
Class Method Summary collapse
- .default_conf ⇒ Object
- .default_conf_name ⇒ Object
- .default_spec_name ⇒ Object
- .dump(user_config_path, user_config) ⇒ Object
- .from(user_config_path) ⇒ Object
- .merge(options, conf, spec = Caravan::Config.default_spec_name) ⇒ Object
- .pretty_puts(conf) ⇒ Object
Class Method Details
.default_conf ⇒ Object
21 22 23 |
# File 'lib/caravan/config.rb', line 21 def default_conf DEFAULT_CONFIG.dup end |
.default_conf_name ⇒ Object
25 26 27 |
# File 'lib/caravan/config.rb', line 25 def default_conf_name DEFAULT_CONFIG_NAME end |
.default_spec_name ⇒ Object
29 30 31 |
# File 'lib/caravan/config.rb', line 29 def default_spec_name DEFAULT_SPEC_NAME end |
.dump(user_config_path, user_config) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# 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) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# 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) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/caravan/config.rb', line 54 def merge(, 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"] = [:src] if .key?(:src) merged_conf["dst"] = [:dst] if .key?(:dst) merged_conf["debug"] = [:debug] if .key?(:debug) merged_conf["deploy_mode"] = [:mode] if .key?(:mode) merged_conf["exclude"] = [:ignore] if .key?(:ignore) merged_conf["once"] = [:once] if .key?(:once) merged_conf end |