Skip to content

Instantly share code, notes, and snippets.

@burtlo
Last active June 13, 2016 20:49
Show Gist options
  • Save burtlo/255be867b34285d954804076b48b20ad to your computer and use it in GitHub Desktop.
Save burtlo/255be867b34285d954804076b48b20ad to your computer and use it in GitHub Desktop.
Using ERB
access_key: <%= access_key %>
secret_id: <%= secret_id %>
namespace :gsub do
desc 'populate a configuration'
task :populate do
content = File.read('config.yml')
content.gsub!('REPLACE_ME_KEY','REAL_KEY')
content.gsub!('REPLACE_ME_ID','REAL_ID')
puts content
end
end
class SecretsConfig
attr_reader :config
def initialize(config = default_config)
@config = config
end
def default_config
'config.yml.erb'
end
def content
File.read(config)
end
def to_yaml
require 'erb'
config_erb = ERB.new(content)
config_erb.result(binding)
end
def access_key
# File.read('')
'my_key2'
end
def secret_id
'my_secret2'
end
end
namespace :erb do
desc 'populate a configuration'
task :populate do
puts SecretsConfig.new.to_yaml
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment