Class: KnifeCookbookDependencies::Lockfile
- Inherits:
-
Object
- Object
- KnifeCookbookDependencies::Lockfile
- Defined in:
- lib/kcd/lockfile.rb
Constant Summary collapse
- DEFAULT_FILENAME =
"#{KCD::DEFAULT_FILENAME}.lock"
Class Method Summary collapse
Instance Method Summary collapse
- #get_cookbook_definition(cookbook) ⇒ Object
-
#initialize(cookbooks) ⇒ Lockfile
constructor
A new instance of Lockfile.
- #remove! ⇒ Object
- #write(filename = DEFAULT_FILENAME) ⇒ Object
Constructor Details
#initialize(cookbooks) ⇒ Lockfile
Returns a new instance of Lockfile.
5 6 7 |
# File 'lib/kcd/lockfile.rb', line 5 def initialize(cookbooks) @cookbooks = cookbooks end |
Class Method Details
.remove! ⇒ Object
35 36 37 |
# File 'lib/kcd/lockfile.rb', line 35 def remove! FileUtils.rm_f DEFAULT_FILENAME end |
Instance Method Details
#get_cookbook_definition(cookbook) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/kcd/lockfile.rb', line 16 def get_cookbook_definition(cookbook) definition = "cookbook '#{cookbook.name}'" if cookbook.from_git? definition += ", :git => '#{cookbook.git_repo}', :ref => '#{cookbook.git_ref || 'HEAD'}'" elsif cookbook.from_path? definition += ", :path => '#{cookbook.local_path}'" else definition += ", :locked_version => '#{cookbook.locked_version}'" end return definition end |
#remove! ⇒ Object
30 31 32 |
# File 'lib/kcd/lockfile.rb', line 30 def remove! self.class.remove! end |
#write(filename = DEFAULT_FILENAME) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/kcd/lockfile.rb', line 9 def write(filename = DEFAULT_FILENAME) content = @cookbooks.map do |cookbook| get_cookbook_definition(cookbook) end.join("\n") File.open(DEFAULT_FILENAME, "wb") { |f| f.write content } end |