rubychef-infracookbookberkshelf

using berkshelf programmatically


i am managing my cookbooks with berkshelf. i would like to play a little bit with the cookbook dependency graph. for instance:

i tried

require 'berkshelf'
Berkshelf::Lockfile.new(file_path: './Berksfile.lock')

but it did not work.

how can berkshelf be invoked programmatically under ruby and achieve the above?


Solution

  • If you have Berksfile, It might be helpful for you.

    
    require 'berkshelf'
    
    # initializing berksfile
    s = Berkshelf::Berksfile.from_file('./find_versions/Berksfile')
    
    #install dependencies to create Berksfile.lock 
    s.install()
    
    # parse lockfile
    s.lockfile().parse()
    
    # find dependencies
    puts s.find('cookbook_name').locked_version