Skip to content

Instantly share code, notes, and snippets.

@flaccid
Created October 24, 2013 02:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flaccid/7130089 to your computer and use it in GitHub Desktop.
Save flaccid/7130089 to your computer and use it in GitHub Desktop.
lightweight ruby class to parse Cheffiles
require 'net/http'
require 'uri'
class LibrarianChefDSLParser
attr_accessor :site, :cookbooks
def initialize(cheffile, &data)
@cheffile = cheffile
@cookbooks = []
data = false
uri = URI.parse(cheffile)
if %w( http https ).include?(uri.scheme)
data = Net::HTTP.get(uri)
else
data = File.read(cheffile)
end
instance_eval data
end
def cheffile
@cheffile
end
def site(*val)
@site = val
end
def cookbook(name, options)
cookbook = { "name" => name, "options" => options }
@cookbooks.push(cookbook)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment