Last active
June 13, 2016 20:49
-
-
Save burtlo/255be867b34285d954804076b48b20ad to your computer and use it in GitHub Desktop.
Using ERB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
access_key: <%= access_key %> | |
secret_id: <%= secret_id %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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