Skip to content

Instantly share code, notes, and snippets.

@fnichol
Created December 20, 2012 06:36
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fnichol/4343327 to your computer and use it in GitHub Desktop.
Save fnichol/4343327 to your computer and use it in GitHub Desktop.
Chef Metadata Chopper!

MetadataChopper

MetadataChopper.extract('metdata.rb') # => [ "rvm", "0.9.1" ]
class MetadataChopper
def self.extract(metadata_file)
mc = new(metadata_file)
[ mc.get_name, mc.get_version ]
end
def initialize(metadata_file)
eval(IO.read(File.expand_path(metadata_file)))
end
def name(arg=nil) ; @name = arg ; end
def get_name ; @name ; end
def version(arg=nil) ; @version = arg ; end
def get_version ; @version ; end
def method_missing(meth, *args, &block)
DSL_METHODS.include?(meth.to_s) ? nil : super
end
DSL_METHODS = %w(description long_description maintainer maintainer_email
license supports depends recommends suggests conflicts provides replaces
attribute grouping recipe)
end
class X<Hash;def self.e(f)x=new(f);[x[:name],x[:version]]end;def initialize(f);eval(IO.read(f),nil,f)end;def method_missing(k,*v)self[k]=v[0] end end
class MetadataChopper < Hash
def self.extract(metadata_file)
mc = new(File.expand_path(metadata_file))
[ mc[:name], mc[:version] ]
end
def initialize(metadata_file)
eval(IO.read(metadata_file), nil, metadata_file)
end
def method_missing(meth, *args, &block)
self[meth] = args.first
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment