Sha256: 25d128bf66d5bad674cff7d1404c6b36ed7058e3e2b77d354a4094fbec6a9223

Contents?: true

Size: 1.34 KB

Versions: 3

Compression:

Stored size: 1.34 KB

Contents

require 'net/http'
require 'uri'
require 'json'

require 'vendorificator/vendor/archive'
require 'vendorificator/hooks/chef_cookbook'

class Vendorificator::Vendor::ChefCookbook < Vendorificator::Vendor::Archive
  include Vendorificator::Hooks::ChefCookbookDependencies

  @method_name = :chef_cookbook
  @category = :cookbooks

  API_PREFIX = 'http://cookbooks.opscode.com/api/v1/cookbooks/'

  def initialize(name, args={}, &block)
    args[:url] ||= true         # to avoid having name treated as url
    args[:filename] ||= "#{name}.tgz"

    super(name, args, &block)
  end

  def api_data(v=nil)
    v = v.gsub(/[^0-9]/, '_') if v
    @api_data ||= {}
    @api_data[v] ||=
      begin
        url = "#{API_PREFIX}#{name}"
        url << "/versions/#{v}" if v
        JSON::load(Net::HTTP.get_response(URI.parse(url)).body)
      end
  end

  def cookbook_data
    @cookbook_data ||= api_data(version)
  end

  def upstream_version
    URI::parse(api_data['latest_version']).path.split('/').last.gsub('_', '.')
  end

  def url
    cookbook_data['file']
  end

  def conjure!
    super
    # Some Opscode Community tarballs include a confusing .git file,
    # we don't want this.
    FileUtils::rm_f '.git'
  end

  def conjure_commit_message
    "Conjured cookbook #{name} version #{version}\nOrigin: #{url}\nChecksum: #{conjured_checksum}\n"
  end

  install!
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vendorificator-0.1.1 lib/vendorificator/vendor/chef_cookbook.rb
vendorificator-0.1.0 lib/vendorificator/vendor/chef_cookbook.rb
vendorificator-0.0.1 lib/vendorificator/vendor/chef_cookbook.rb