Class: Rum::Docker::Image
- Inherits:
-
Object
- Object
- Rum::Docker::Image
- Extended by:
- AttrCallable
- Includes:
- Enumerable
- Defined in:
- lib/rumrunner/docker.rb
Overview
Docker image object.
Class Method Summary collapse
-
.parse(string_or_symbol) ⇒ Object
Parse a string as a Docker image reference.
Instance Method Summary collapse
-
#each ⇒ Object
Yield each non-nil component of the image reference in order.
-
#family ⇒ Object
Get the image reference without the @tag component.
-
#initialize(name:, registry: nil, username: nil, tag: nil, &block) ⇒ Image
constructor
Initialize image by reference component.
-
#registry ⇒ Object
Access components of the image reference by method.
-
#to_s ⇒ Object
Convert the image reference to string.
Methods included from AttrCallable
Constructor Details
#initialize(name:, registry: nil, username: nil, tag: nil, &block) ⇒ Image
Initialize image by reference component. Evaluates &block if given.
249 250 251 252 253 254 255 |
# File 'lib/rumrunner/docker.rb', line 249 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
Parse a string as a Docker image reference
Example:
Image.parse("image")
Image.parse("image:tag")
Image.parse("username/image")
Image.parse("username/image:tag")
Image.parse("registry:5000/username/image")
Image.parse("registry:5000/username/image:tag")
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
# File 'lib/rumrunner/docker.rb', line 288 def parse(string_or_symbol) string = string_or_symbol.to_s slash_count = string.count("/") # image[:tag] if slash_count.zero? name, tag = string.split(/:/) new name: name, tag: tag # username/image[:tag] elsif slash_count == 1 username, name_tag = string.split(/\//) name, tag = name_tag.split(/:/) new name: name, username: username, tag: tag # registry/username/image[:tag] else 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
#each ⇒ Object
Yield each non-nil component of the image reference in order.
259 260 261 |
# File 'lib/rumrunner/docker.rb', line 259 def each [@registry, @username, @name, @tag || :latest].compact.each{|x| yield x.to_s } end |
#family ⇒ Object
Get the image reference without the @tag component.
265 266 267 |
# File 'lib/rumrunner/docker.rb', line 265 def family File.join(*[@registry, @username, @name].compact.map(&:to_s)) end |
#registry ⇒ Object
Access components of the image reference by method.
244 |
# File 'lib/rumrunner/docker.rb', line 244 attr_method_accessor :registry, :username, :name, :tag |
#to_s ⇒ Object
Convert the image reference to string.
271 272 273 |
# File 'lib/rumrunner/docker.rb', line 271 def to_s "#{family}:#{@tag || :latest}" end |