module Dockerspec::Helper::MultipleSourcesDescription
Methods to generate the correct object description for objects that has a source attribute.
Shortens the docker IDs automatically.
Requirements:
-
`source` method: Returns the source you are using to generating your
object.
-
`:@options` attribute: The options array with the configuration
options, including the source.
Used by the {Dockerspec::Builder} and {Dockerspec::Runner} classes.
Public Instance Methods
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
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
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
Generates a description of a file.
@example
self.description_from_template("mydir") #=> "mydir"
@return [String] A description.
@api private
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