lib/berkshelf.rb in berkshelf-2.0.18 vs lib/berkshelf.rb in berkshelf-3.0.0.beta1

- old
+ new

@@ -1,8 +1,8 @@ -require 'active_support/core_ext' +require 'buff/extensions' require 'archive/tar/minitar' -require 'chozo/core_ext' +require 'celluloid' require 'digest/md5' require 'forwardable' require 'hashie' require 'json' require 'pathname' @@ -10,28 +10,28 @@ require 'solve' require 'thor' require 'tmpdir' require 'uri' require 'zlib' -require 'rbzip2' +JSON.create_id = nil + require_relative 'berkshelf/core_ext' -require_relative 'berkshelf/errors' -require_relative 'berkshelf/mixin' require_relative 'berkshelf/thor_ext' -JSON.create_id = nil - module Berkshelf + require_relative 'berkshelf/errors' + require_relative 'berkshelf/mixin' + DEFAULT_FILENAME = 'Berksfile'.freeze class << self include Berkshelf::Mixin::Logging + attr_writer :berkshelf_path attr_accessor :ui attr_accessor :logger - attr_writer :cookbook_store # @return [Pathname] def root @root ||= Pathname.new(File.expand_path('../', File.dirname(__FILE__))) end @@ -48,26 +48,47 @@ # can be overridden by specifying a value for the ENV variable # 'BERKSHELF_PATH'. # # @return [String] def berkshelf_path - ENV['BERKSHELF_PATH'] || File.expand_path('~/.berkshelf') + @berkshelf_path || ENV['BERKSHELF_PATH'] || File.expand_path('~/.berkshelf') end + # The Berkshelf configuration. + # + # @return [Berkshelf::Config] + def config + Berkshelf::Config.instance + end + + # @param [Berkshelf::Config] + def config=(config) + Berkshelf::Config.set_config(config) + end + # The Chef configuration file. # # @return [Berkshelf::Chef::Config] def chef_config - @chef_config ||= Berkshelf::Chef::Config.load + Berkshelf::Chef::Config.instance end - # Set the Chef configuration file. - # - # @param [Berkshelf::Chef::Config] new_config - # the new configuration file to use - attr_writer :chef_config + # @param [Berkshelf::Chef::Config] + def chef_config=(config) + Berkshelf::Chef::Config.set_config(config) + end + # Initialize the filepath for the Berkshelf path.. + def initialize_filesystem + FileUtils.mkdir_p(berkshelf_path, mode: 0755) + + unless File.writable?(berkshelf_path) + raise InsufficientPrivledges, "You do not have permission to write to '#{berkshelf_path}'!" + + " Please either chown the directory or use a different filepath." + end + end + # @return [String] def tmp_dir File.join(berkshelf_path, 'tmp') end @@ -78,17 +99,13 @@ def mktmpdir FileUtils.mkdir_p(tmp_dir) Dir.mktmpdir(nil, tmp_dir) end - def cookbooks_dir - File.join(berkshelf_path, 'cookbooks') - end - # @return [Berkshelf::CookbookStore] def cookbook_store - @cookbook_store ||= CookbookStore.new(cookbooks_dir) + CookbookStore.instance end # Get the appropriate Formatter object based on the formatter # classes that have been registered. # @@ -120,30 +137,32 @@ end end end end +require_relative 'berkshelf/api_client' require_relative 'berkshelf/base_generator' require_relative 'berkshelf/berksfile' require_relative 'berkshelf/cached_cookbook' require_relative 'berkshelf/chef' require_relative 'berkshelf/cli' require_relative 'berkshelf/community_rest' require_relative 'berkshelf/cookbook_generator' -require_relative 'berkshelf/cookbook_source' require_relative 'berkshelf/cookbook_store' require_relative 'berkshelf/config' +require_relative 'berkshelf/dependency' require_relative 'berkshelf/downloader' require_relative 'berkshelf/formatters' require_relative 'berkshelf/git' require_relative 'berkshelf/init_generator' +require_relative 'berkshelf/installer' require_relative 'berkshelf/location' require_relative 'berkshelf/lockfile' require_relative 'berkshelf/logger' require_relative 'berkshelf/resolver' -require_relative 'berkshelf/test' if ENV['RUBY_ENV'] == 'test' +require_relative 'berkshelf/source' +require_relative 'berkshelf/source_uri' require_relative 'berkshelf/ui' require_relative 'berkshelf/version' -Ridley.logger = Berkshelf.logger = Logger.new(STDOUT) +Ridley.logger = Celluloid.logger = Berkshelf.logger = Logger.new(STDOUT) Berkshelf.logger.level = Logger::WARN -Celluloid.logger.level = Logger::FATAL if defined?(Celluloid)