Class: Vendorificator::Vendor::ChefCookbook

Inherits:
Archive show all
Includes:
Hooks::ChefCookbookDependencies
Defined in:
lib/vendorificator/vendor/chef_cookbook.rb

Constant Summary collapse

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

Instance Attribute Summary

Attributes inherited from Archive

#conjured_checksum, #conjured_filesize

Attributes inherited from Vendorificator::Vendor

#args, #block, #environment, #name, #segment

Instance Method Summary collapse

Methods included from Hooks::ChefCookbookDependencies

#compute_dependencies!

Methods inherited from Vendorificator::Vendor

#===, arg_reader, #before_conjure!, #compute_dependencies!, #git_add_extra_paths, #group, #inspect, #metadata, #version

Constructor Details

#initialize(environment, name, args = {}, &block) ⇒ ChefCookbook

Returns a new instance of ChefCookbook.



17
18
19
20
21
22
# File 'lib/vendorificator/vendor/chef_cookbook.rb', line 17

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

Instance Method Details

#api_data(v = nil) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/vendorificator/vendor/chef_cookbook.rb', line 24

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
      MultiJson::load(Net::HTTP.get_response(URI.parse(url)).body)
    end
end

#conjure!Object



47
48
49
50
51
52
# File 'lib/vendorificator/vendor/chef_cookbook.rb', line 47

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

#conjure_commit_messageObject



54
55
56
# File 'lib/vendorificator/vendor/chef_cookbook.rb', line 54

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

#cookbook_dataObject



35
36
37
# File 'lib/vendorificator/vendor/chef_cookbook.rb', line 35

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

#upstream_versionObject



39
40
41
# File 'lib/vendorificator/vendor/chef_cookbook.rb', line 39

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

#urlObject



43
44
45
# File 'lib/vendorificator/vendor/chef_cookbook.rb', line 43

def url
  cookbook_data['file']
end