module Dockerspec::Helper::MultipleSourcesDescription

Methods to generate the correct object description for objects that has a source attribute.

Shortens the docker IDs automatically.

Requirements:

Used by the {Dockerspec::Builder} and {Dockerspec::Runner} classes.

Public Instance Methods

description(prefix) click to toggle source

Generates a description of the object.

@example

self.description('Docker Build from')
  #=> "Docker Build from path: \".\""

@param prefix [String] The prefix to add to the description.

@return [String] The object description.

@api private

# File lib/dockerspec/helper/multiple_sources_description.rb, line 61
def description(prefix)
  value = @options[source]
  desc = send("description_from_#{source}", value)
  "#{prefix} #{source.to_s.tr('_', ' ')}: \"#{desc}\""
end

Protected Instance Methods

description_from_docker(str) click to toggle source

Generates an adequate description of a Docker object description.

Essentially it shortens the docker identifiers.

@example

self.description_from_docker_object('debian') #=> "debian"
self.description_from_docker_object('92cc98ab560a92cc98ab560[...]')
  #=> "92cc98ab560a"

@param str [String] The description.

@return [String] The description, shortened if necessary.

@api private

# File lib/dockerspec/helper/multiple_sources_description.rb, line 85
def description_from_docker(str)
  return str unless str =~ /^[0-9a-f]+$/
  str[0..11]
end
Also aliased as: description_from_id
description_from_file(str) click to toggle source

Generates a description of a file.

Basically expands the path.

@example

self.description_from_file("mydir") #=> "mydir"

@return [String] A description.

@api private

# File lib/dockerspec/helper/multiple_sources_description.rb, line 125
def description_from_file(str)
  File.expand_path(str)
end
Also aliased as: description_from_path
description_from_id(str)

Generates a description from Docker ID.

description_from_path(str)

Generates a description of a file.

@example

self.description_from_template("mydir") #=> "mydir"

@return [String] A description.

@api private

description_from_string(str) click to toggle source

Generates a description from string.

shortens the string.

@example

self.description_from_string #=> "FROM nginx:1..."

@return [String] A description.

@api private

# File lib/dockerspec/helper/multiple_sources_description.rb, line 107
def description_from_string(str)
  len = 12
  return str unless str.length > len
  "#{str[0..len - 1]}..." # Is this length correct?
end