Module: VagrantBolt::Util::Config
- Defined in:
- lib/vagrant-bolt/util/config.rb
Class Method Summary collapse
-
.full_path(path, root_path) ⇒ String
Convert a path to the absolute path if it is relative.
-
.merge_config(local, other) ⇒ Object
Merge config objects overriding Nil and UNSET_VALUE Since the configs have been finalized they will have
nilvalues Arrays will be merged and override parent non arrays instead of UNSET_VALUE. -
.relative_path(path, root_path) ⇒ String
Convert a path to the relative path from the current directory.
Class Method Details
.full_path(path, root_path) ⇒ String
Convert a path to the absolute path if it is relative
39 40 41 42 43 |
# File 'lib/vagrant-bolt/util/config.rb', line 39 def self.full_path(path, root_path) return path if path.nil? || root_path.nil? (Pathname.new path).absolute? ? path : File.(path, root_path) end |
.merge_config(local, other) ⇒ Object
Merge config objects overriding Nil and UNSET_VALUE
Since the configs have been finalized they will have nil values
Arrays will be merged and override parent non arrays
instead of UNSET_VALUE
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/vagrant-bolt/util/config.rb', line 16 def self.merge_config(local, other) result = local.class.new [other, local].each do |obj| obj.instance_variables.each do |key| value = obj.instance_variable_get(key) if value.is_a? Array res_value = result.instance_variable_get(key) value = (value + res_value).uniq if res_value.is_a? Array elsif value.is_a? Hash res_value = result.instance_variable_get(key) value = res_value.merge(value) if res_value.is_a? Hash end result.instance_variable_set(key, value) if value != Vagrant::Plugin::V2::Config::UNSET_VALUE && !value.nil? end end result.finalize! result end |
.relative_path(path, root_path) ⇒ String
Convert a path to the relative path from the current directory
49 50 51 52 53 54 |
# File 'lib/vagrant-bolt/util/config.rb', line 49 def self.relative_path(path, root_path) return path if path.nil? absolute_path = Pathname.new full_path(path, root_path) absolute_path.relative_path_from(Pathname.getwd).to_s end |