Sha256: 8b0f644a37cddeab7d4a4d84b44b8596fcab9ddf7dba88a8c8af6db720478897

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 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(environment, name, args={}, &block)
    args[:url] ||= true         # to avoid having name treated as url
    args[:filename] ||= "#{name}.tgz"

    super(environment, 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

1 entries across 1 versions & 1 rubygems

Version Path
vendorificator-0.2.0 lib/vendorificator/vendor/chef_cookbook.rb