Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

Commit

Permalink
Merge pull request #149 from opscode/sersut/gen-template-fix
Browse files Browse the repository at this point in the history
Make sure the context is set right while generating a template.
  • Loading branch information
Serdar Sutay committed Sep 2, 2014
2 parents 9372701 + 5108494 commit 9ca725c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

# Unreleased

* Fix a regression where `chef generate template` fails with
`undefined method `content_source' for #<chefdk::generator::context:0x00000003e37af8>`
in 2.1.1

## Last Release: 0.2.1

Other than some minor bug fixes, here is a list of included changes:
Expand Down
3 changes: 2 additions & 1 deletion lib/chef-dk/command/generator_commands/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module GeneratorCommands
# chef generate template [path/to/cookbook_root] name --source=source_file
class Template < CookbookCodeFile

option :content_source,
option :source,
:short => "-s SOURCE_FILE",
:long => "--source SOURCE_FILE",
:description => "Copy content from SOURCE_FILE"
Expand All @@ -38,6 +38,7 @@ def recipe

def setup_context
super
Generator.add_attr_to_context(:content_source, config[:source])
end
end
end
Expand Down
17 changes: 16 additions & 1 deletion lib/chef-dk/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,22 @@ module Generator
# This is here to hold attr_accessor data for Generator context variables
class Context
def self.add_attr(name)
attr_accessor(name)
@attributes ||= [ ]

if !@attributes.include?(name)
@attributes << name
attr_accessor(name)
end
end

def self.reset
return if @attributes.nil?

@attributes.each do |attr|
remove_method(attr)
end

@attributes = nil
end
end

Expand Down
5 changes: 4 additions & 1 deletion spec/shared/a_file_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ def generator_context
reset_tempdir
end

after(:each) do
ChefDK::Generator::Context.reset
end

context "when argv is empty" do
let(:argv) { [] }

Expand Down Expand Up @@ -118,4 +122,3 @@ def generator_context
end

end

0 comments on commit 9ca725c

Please sign in to comment.