Skip to content

Commit

Permalink
stubbed the cloudformation ERB template
Browse files Browse the repository at this point in the history
  • Loading branch information
pghalliday committed Oct 29, 2015
1 parent 213d6d5 commit 8eda0ad
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 10 deletions.
34 changes: 33 additions & 1 deletion lib/formatron/configuration/cloud_formation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,40 @@ class Formatron
class Configuration
# Generates the CloudFormation templates
module CloudFormation
def self.template(_formatronfile)
# exports params to CloudFormation ERB template
class Template
attr_reader :name, :bucket, :configuration

def initialize(name:, bucket:, configuration:)
@name = name
@bucket = bucket
@configuration = configuration
end
end

def self.template(formatronfile)
template = _template_path
erb = ERB.new File.read(template)
erb.filename = template
erb_template = erb.def_class Template, 'render()'
erb_template.new(
name: formatronfile.name,
bucket: formatronfile.bucket,
configuration: formatronfile.bootstrap
).render
end

def self._template_path
File.join(
File.dirname(File.expand_path(__FILE__)),
File.basename(__FILE__, '.rb'),
'bootstrap.json.erb'
)
end

private_class_method(
:_template_path
)
end
end
end
Empty file.
1 change: 1 addition & 0 deletions lib/formatron/generators/bootstrap/formatronfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def self.write(directory, params)
def self._content(params)
template = File.join(
File.dirname(File.expand_path(__FILE__)),
File.basename(__FILE__, '.rb'),
'Formatronfile.erb'
)
erb = ERB.new File.read(template)
Expand Down
50 changes: 41 additions & 9 deletions spec/formatron/configuration/cloud_formation_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,53 @@ class Formatron
# namespacing for tests
class Configuration
describe CloudFormation do
describe '::template' do
include FakeFS::SpecHelpers

name = 'name'
bucket = 'bucket'
bootstrap = 'bootstrap'
dir = File.expand_path(
File.join(
File.dirname(File.expand_path(__FILE__)),
'../../../lib/formatron/configuration/cloud_formation'
)
)

before :each do
FileUtils.mkdir_p dir
end

context 'with a bootstrap configuration' do
before(:each) do
File.write(
File.join(dir, 'bootstrap.json.erb'),
<<-EOH.gsub(/^ {14}/, '')
<%= name %>
<%= bucket %>
<%= configuration %>
EOH
)
@formatronfile = instance_double(
'Formatron::Configuration::Formatronfile'
)
allow(@formatronfile).to receive(:name) { name }
allow(@formatronfile).to receive(:bucket) { bucket }
allow(@formatronfile).to receive(:bootstrap) { bootstrap }
end

skip 'should return the CloudFormation template for ' \
'a Formatron configuration' do
expect(
CloudFormation.template(
@formatronfile
)
).to eql <<-EOH.gsub(/^ {8}/, '')
EOH
describe '::template' do
it 'should return the CloudFormation template for ' \
'a Formatron configuration' do
expect(
CloudFormation.template(
@formatronfile
)
).to eql <<-EOH.gsub(/^ {14}/, '')
#{name}
#{bucket}
#{bootstrap}
EOH
end
end
end
end
Expand Down

0 comments on commit 8eda0ad

Please sign in to comment.