Class: Rum::Docker::Image

Inherits:
Object
  • Object
show all
Extended by:
AttrCallable
Includes:
Enumerable
Defined in:
lib/rumrunner/docker.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AttrCallable

attr_method_accessor

Constructor Details

#initialize(name:, registry: nil, username: nil, tag: nil, &block) ⇒ Image

Returns a new instance of Image.



135
136
137
138
139
140
141
# File 'lib/rumrunner/docker.rb', line 135

def initialize(name:, registry:nil, username:nil, tag:nil, &block)
  @registry = registry
  @username = username
  @name     = name
  @tag      = tag
  instance_eval(&block) if block_given?
end

Class Method Details

.parse(string_or_symbol) ⇒ Object



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/rumrunner/docker.rb', line 156

def parse(string_or_symbol)
  string = string_or_symbol.to_s
  if string.count("/").zero? && string.count(":").zero?
    # image
    new name: string
  elsif string.count("/").zero?
    # image:tag
    name, tag = string.split(/:/)
    new name: name, tag: tag
  elsif string.count("/") == 1 && string.count(":").zero?
    # username/image
    username, name = string.split(/\//)
    new name: name, username: username
  elsif string.count("/") == 1
    # username/image:tag
    username, name_tag = string.split(/\//)
    name, tag          = name_tag.split(/:/)
    new name: name, username: username, tag: tag
  else
    # registry/username/image[:tag]
    registry, username, name_tag = string.split(/\//)
    name, tag                    = name_tag.split(/:/)
    new name: name, registry: registry, username: username, tag: tag
  end
end

Instance Method Details

#eachObject



143
144
145
# File 'lib/rumrunner/docker.rb', line 143

def each
  [@registry, @username, @name, @tag].compact.each{|x| yield x }
end

#familyObject



147
148
149
# File 'lib/rumrunner/docker.rb', line 147

def family
  File.join *[@registry, @username, @name].compact.map(&:to_s)
end

#to_sObject



151
152
153
# File 'lib/rumrunner/docker.rb', line 151

def to_s
  "#{family}:#{@tag || :latest}"
end