class Dip::Environment
Constants
- SPECIAL_VARS
- VAR_REGEX
Attributes
vars[R]
Public Class Methods
new(default_vars)
click to toggle source
# File lib/dip/environment.rb, line 12 def initialize(default_vars) @vars = {} merge(default_vars || {}) end
Public Instance Methods
[](name)
click to toggle source
# File lib/dip/environment.rb, line 25 def [](name) vars.fetch(name) { ENV[name] } end
[]=(key, value)
click to toggle source
# File lib/dip/environment.rb, line 33 def []=(key, value) @vars[key] = value end
fetch(name, &block)
click to toggle source
# File lib/dip/environment.rb, line 29 def fetch(name, &block) vars.fetch(name) { ENV.fetch(name, &block) } end
interpolate(value)
click to toggle source
# File lib/dip/environment.rb, line 37 def interpolate(value) value.gsub(VAR_REGEX) do |match| var_name = Regexp.last_match[:var_name] if special_vars.key?(var_name) fetch(var_name) { send(special_vars[var_name]) } else fetch(var_name) { match } end end end
Also aliased as: replace
merge(new_vars)
click to toggle source
# File lib/dip/environment.rb, line 18 def merge(new_vars) new_vars.each do |key, value| key = key.to_s @vars[key] = ENV.fetch(key) { interpolate(value.to_s) } end end
Private Instance Methods
find_os()
click to toggle source
# File lib/dip/environment.rb, line 59 def find_os @dip_os ||= Gem::Platform.local.os end
find_work_dir_rel_path()
click to toggle source
# File lib/dip/environment.rb, line 63 def find_work_dir_rel_path @find_work_dir_rel_path ||= Pathname.getwd.relative_path_from(Dip.config.file_path.parent).to_s end
special_vars()
click to toggle source
# File lib/dip/environment.rb, line 53 def special_vars @special_vars ||= SPECIAL_VARS.each_with_object({}) do |key, memo| memo["DIP_#{key.to_s.upcase}"] = "find_#{key}" end end