MetadataChopper.extract('metdata.rb') # => [ "rvm", "0.9.1" ]
Created
December 20, 2012 06:36
-
-
Save fnichol/4343327 to your computer and use it in GitHub Desktop.
Chef Metadata Chopper!
This file contains hidden or 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
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 |
This file contains hidden or 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
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 |
This file contains hidden or 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
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