Created
September 19, 2012 19:52
-
-
Save mlafeldt/3751833 to your computer and use it in GitHub Desktop.
Process metadata of Chef cookbooks
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
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
#!/usr/bin/env ruby | |
require 'chef/cookbook/metadata' | |
require 'chef/version_class' | |
# Add increment methods to Chef::Version | |
class Chef | |
class Version | |
def increment_patch | |
@patch += 1 | |
self | |
end | |
def increment_minor | |
@minor += 1 | |
self | |
end | |
def increment_major | |
@major += 1 | |
self | |
end | |
end | |
end | |
metadata_file = ARGV.first || 'metadata.rb' | |
metadata = Chef::Cookbook::Metadata.new | |
metadata.from_file(metadata_file) | |
puts "#{metadata.name} #{metadata.version}" | |
new_version = Chef::Version.new(metadata.version).increment_patch | |
puts "#{metadata.name} #{new_version}" |
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
#!/usr/bin/env ruby | |
require 'chef/cookbook/metadata' | |
metadata_file = ARGV.first || 'metadata.rb' | |
metadata = Chef::Cookbook::Metadata.new | |
metadata.from_file(metadata_file) | |
puts "#{metadata.name} #{metadata.version}" | |
metadata.dependencies.each do |cookbook, version| | |
puts "#{cookbook} #{version}" | |
end |
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
#!/usr/bin/env ruby | |
class CookbookMetadata | |
class << self | |
def from_file(file) | |
content = File.read(file) | |
object = new(file) | |
object.load(content) | |
end | |
end | |
attr_reader :cb_name, :cb_version, :dependencies | |
def initialize(file) | |
@file = file | |
@cb_name = nil | |
@cb_version = nil | |
@dependencies = Hash.new | |
end | |
def name(value) | |
@cb_name = value | |
end | |
def version(value) | |
@cb_version = value | |
end | |
def depends(cb_name, version=nil) | |
@dependencies[cb_name] = version || ">= 0.0.0" | |
end | |
%w(maintainer maintainer_email license description | |
long_description recipe supports).each do |method| | |
define_method(method.to_sym) do |*args| | |
end | |
end | |
def load(content) | |
instance_eval(content) | |
self | |
end | |
end | |
metadata_file = ARGV.first || 'metadata.rb' | |
metadata = CookbookMetadata.from_file(metadata_file) | |
puts "#{metadata.cb_name} #{metadata.cb_version}" | |
metadata.dependencies.each do |cookbook, version| | |
puts "#{cookbook} #{version}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Inspired by https://github.com/RiotGames/berkshelf/blob/v0.4.0/lib/berkshelf/berksfile.rb#L140-169