Skip to content

Instantly share code, notes, and snippets.

@stevenhaddox
Last active May 7, 2019 02:29
Show Gist options
  • Save stevenhaddox/8850903 to your computer and use it in GitHub Desktop.
Save stevenhaddox/8850903 to your computer and use it in GitHub Desktop.
Dynamic Gemfile Sources
---
gem_sources:
- 'https://rubygems.org'
- 'http://rubygems.org'
# Dynamically load gem sources from YAML config file
require 'yaml'
# See if we have a custom gem_sources.yml file, if not use the .example default.
if File.exist? File.expand_path("../config/gem_sources.yml", __FILE__)
gem_sources_file = File.expand_path("../config/gem_sources.yml", __FILE__)
puts "NOTE: Using the following gem sources from `config/gem_sources.yml`:"
@custom_gem_source = true
else
gem_sources_file = File.expand_path("../config/gem_sources.yml.example", __FILE__)
end
sources_yaml = YAML::load(File.read(gem_sources_file))
sources_yaml['gem_sources'].each do |source_str|
puts source_str if @custom_gem_source
source source_str
end
# Put your gems below as usual
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment