lib/berkshelf.rb in berkshelf-0.3.7 vs lib/berkshelf.rb in berkshelf-0.4.0.rc1

- old
+ new

@@ -1,21 +1,23 @@ require 'pathname' -require 'dep_selector' require 'zlib' require 'archive/tar/minitar' +require 'solve' require 'chef/knife' require 'chef/rest' require 'chef/platform' require 'chef/cookbook/metadata' +require 'chef/cookbook_version' require 'berkshelf/version' require 'berkshelf/core_ext' require 'berkshelf/errors' Chef::Config[:cache_options][:path] = Dir.mktmpdir module Berkshelf + DEFAULT_CONFIG = File.expand_path(ENV["CHEF_CONFIG"] || "~/.chef/knife.rb") DEFAULT_STORE_PATH = File.expand_path("~/.berkshelf").freeze DEFAULT_FILENAME = 'Berksfile'.freeze autoload :Cli, 'berkshelf/cli' autoload :DSL, 'berkshelf/dsl' @@ -35,10 +37,12 @@ class << self attr_accessor :ui attr_accessor :cookbook_store attr_accessor :downloader + attr_writer :config_path + def root @root ||= Pathname.new(File.expand_path('../', File.dirname(__FILE__))) end def ui @@ -58,9 +62,23 @@ @cookbook_store ||= CookbookStore.new(berkshelf_path) end def downloader @downloader ||= Downloader.new(cookbook_store) + end + + def config_path + @config_path ||= DEFAULT_CONFIG + end + + # Load the config found at the given path as the Chef::Config. If no path is specified + # the value of Berkshelf.chef_config will be used. + # + # @param [String] path + def load_config(path = config_path) + Chef::Config.from_file(File.expand_path(path)) + rescue Errno::ENOENT + raise KnifeConfigNotFound, "Attempted to load configuration from: '#{path}' but not found." end # Ascend the directory structure from the given path to find a # metadata.rb file of a Chef Cookbook. If no metadata.rb file # was found, nil is returned.