Class: OSwitch::Image

Inherits:
Struct
  • Object
show all
Extended by:
Enumerable
Defined in:
lib/oswitch/image.rb,
lib/oswitch/image.rb

Overview

Captures a docker image’s metadata.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#createdObject

Returns the value of attribute created

Returns:

  • (Object)

    the current value of created



3
4
5
# File 'lib/oswitch/image.rb', line 3

def created
  @created
end

#idObject

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



3
4
5
# File 'lib/oswitch/image.rb', line 3

def id
  @id
end

#repositoryObject

Returns the value of attribute repository

Returns:

  • (Object)

    the current value of repository



3
4
5
# File 'lib/oswitch/image.rb', line 3

def repository
  @repository
end

#sizeObject

Returns the value of attribute size

Returns:

  • (Object)

    the current value of size



3
4
5
# File 'lib/oswitch/image.rb', line 3

def size
  @size
end

#tagObject

Returns the value of attribute tag

Returns:

  • (Object)

    the current value of tag



3
4
5
# File 'lib/oswitch/image.rb', line 3

def tag
  @tag
end

Class Method Details

.allObject



12
13
14
15
# File 'lib/oswitch/image.rb', line 12

def all
  `docker images`.split("\n").drop(1).
    map{|l| Image.new(*l.split(/\s{2,}/))}
end

.each(&block) ⇒ Object



17
18
19
# File 'lib/oswitch/image.rb', line 17

def each(&block)
  all.each(&block)
end

.exists?(imgname) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/oswitch/image.rb', line 28

def exists?(imgname)
  !!get(imgname)
end

.get(imgname) ⇒ Object



21
22
23
24
25
26
# File 'lib/oswitch/image.rb', line 21

def get(imgname)
  repository, tag = imgname.split(':')
  return if not repository or repository.empty?
  tag = 'latest' if not tag or tag.empty?
  find {|img| img.repository == repository and img.tag == tag}
end