Skip to content

Instantly share code, notes, and snippets.

@jjasghar
Forked from burtlo/Rakefile
Created June 13, 2016 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jjasghar/088a4a16243ff44aaae5d23ccfe59771 to your computer and use it in GitHub Desktop.
Save jjasghar/088a4a16243ff44aaae5d23ccfe59771 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