class PoiseArchive::Resources::PoiseArchive::Resource

A `poise_archive` resource to unpack archives.

@provides poise_archive @action unpack @example

poise_archive '/opt/myapp.tgz'

@example Downloading from a URL with options

poise_archive ['http://example.com/myapp.zip', {headers: {'Authentication' => '...'}}] do
  destination '/opt/myapp'
end

Constants

BASENAME_IGNORE

Filename components to ignore. @api private

URL_PATHS

Regexp for URL-like paths. @api private

Public Class Methods

new(name, run_context) click to toggle source
Calls superclass method
# File lib/poise_archive/resources/poise_archive.rb, line 82
def initialize(name, run_context)
  @raw_name = name # Capture this before it gets coerced to a string.
  super
end

Public Instance Methods

absolute_path() click to toggle source

Expand a relative file path against `Chef::Config`. For URLs it returns the cache file path.

@api private @return [String]

# File lib/poise_archive/resources/poise_archive.rb, line 104
def absolute_path
  if is_url?
    # Use the last path component without the query string plus the name
    # of the resource in Base64. This should be both mildly readable and
    # also unique per invocation.
    url_part = URI(path).path.split(/\//).last
    base64_name = Base64.strict_encode64(name).gsub(/\=/, '')
    ::File.join(Chef::Config[:file_cache_path], "#{base64_name}_#{url_part}")
  else
    ::File.expand_path(path, Chef::Config[:file_cache_path])
  end
end
is_url?() click to toggle source

Check if the source path is a URL.

@api private @return [Boolean]

# File lib/poise_archive/resources/poise_archive.rb, line 95
def is_url?
  path =~ URL_PATHS
end
merged_source_properties() click to toggle source

Merge the explicit source properties with the array form of the name.

@api private @return [Hash]

# File lib/poise_archive/resources/poise_archive.rb, line 121
def merged_source_properties
  if @raw_name.is_a?(Array) && @raw_name[1]
    source_properties.merge(@raw_name[1])
  else
    source_properties
  end
end

Private Instance Methods

default_destination() click to toggle source

Default value for the {#destination} property

@api private @return [String]

# File lib/poise_archive/resources/poise_archive.rb, line 139
def default_destination
  if is_url?
    raise ValueError.new("Destination for URL-based archive #{self} must be specified explicitly")
  else
    ::File.join(::File.dirname(absolute_path), ::File.basename(path).gsub(BASENAME_IGNORE, ''))
  end
end