class Copper::DataTypes::Image
Public Class Methods
new(value)
click to toggle source
# File lib/copper/data_types/image.rb, line 5 def initialize(value) if value.is_a?(::String) @value = deconstruct_image(value) else @value = value end end
Public Instance Methods
fqin()
click to toggle source
# File lib/copper/data_types/image.rb, line 33 def fqin @value[:fqin] end
name()
click to toggle source
# File lib/copper/data_types/image.rb, line 21 def name @value[:name] end
registry()
click to toggle source
# File lib/copper/data_types/image.rb, line 17 def registry @value[:registry] end
registry_url()
click to toggle source
# File lib/copper/data_types/image.rb, line 29 def registry_url @value[:registry_url] end
tag()
click to toggle source
# File lib/copper/data_types/image.rb, line 25 def tag @value[:tag] end
to_s()
click to toggle source
# File lib/copper/data_types/image.rb, line 13 def to_s @value.to_s end
Private Instance Methods
deconstruct_image(source_image)
click to toggle source
# File lib/copper/data_types/image.rb, line 39 def deconstruct_image(source_image) full_image = source_image.strip full_name = "library/#{full_image}" unless full_image.include?('/') full_image = "library/#{full_image}" unless full_image.include?('/') full_image = "#{full_image}:latest" unless full_image.include?(':') # default proto = 'https://' if full_image =~ /^https/ proto = 'https://' full_image = full_image.gsub(/https:\/\//, '') elsif full_image =~ /^http/ proto = 'http://' full_image = full_image.gsub(/http:\/\//, '') end # trim / from front and back full_image = full_image.gsub(/^\//, '').gsub(/\/$/, '') # figure out registry if full_image =~ /^library\// || full_image.split('/').count < 3 # its docker io registry = 'index.docker.io' else registry = full_image.gsub(/\/.*/, '') end # figure out image name full_image = full_image.gsub(/#{registry}(\/(v|V)(1|2)|)/i,'').gsub(/^\//, '').gsub(/\/$/, '') image_parts = full_image.split(':') image_name = image_parts[0] image_tag = image_parts[1] # recombine for registry registry_url = "#{proto}#{registry}" fqin = "#{registry_url}/#{full_image}" # return information return ImageClass.new({ fqin: fqin, registry: registry, registry_url: registry_url, name: image_name, tag: image_tag }) end