class Halite::Berkshelf::Helper
Helper
class to monkeypatch global gem support in to Berkshelf
.
@since 1.0.0 @api private
Public Class Methods
install(*args)
click to toggle source
# File lib/halite/berkshelf/helper.rb, line 30 def self.install(*args) new(*args).install end
new()
click to toggle source
# File lib/halite/berkshelf/helper.rb, line 34 def initialize end
Public Instance Methods
install()
click to toggle source
Install the two patches.
@return [void]
# File lib/halite/berkshelf/helper.rb, line 40 def install # Switch this to use Module#prepend at some point when I stop caring about Ruby 1.9. ::Berkshelf::Berksfile.class_exec do old_sources = instance_method(:sources) define_method(:sources) do original_sources = begin old_sources.bind(self).call rescue ::Berkshelf::NoAPISourcesDefined # We don't care, there will be a source [] end # Make sure we never add two halite sources. original_sources.reject {|s| s.is_a?(::Halite::Berkshelf::Source) } + [::Halite::Berkshelf::Source.new(self)] end end # Inject support for the :halite location type ::Berkshelf::Downloader.class_exec do old_try_download = instance_method(:try_download) define_method(:try_download) do |source, name, version| remote_cookbook = source.cookbook(name, version) if remote_cookbook && remote_cookbook.location_type == :halite tmp_dir = Dir.mktmpdir Halite.convert(remote_cookbook.location_path, tmp_dir) tmp_dir else old_try_download.bind(self).call(source, name, version) end end end end