Method: Gitenv::Config#include

Defined in:
lib/gitenv/config.rb

#include(other_config_file, optional: false) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/gitenv/config.rb', line 50

def include(other_config_file, optional: false)
  raise 'Only absolute paths can be included' unless Pathname.new(other_config_file).absolute?

  absolute_path = File.expand_path(other_config_file)
  unless File.exist?(absolute_path)
    raise "Cannot find file to include #{absolute_path}" unless optional

    return
  end

  contents = File.open(absolute_path, 'r').read
  instance_eval contents, absolute_path
end