Class: DC::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/dc.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, directory: name) ⇒ Image

Returns a new instance of Image.



162
163
164
165
166
# File 'lib/dc.rb', line 162

def initialize name, directory: name
  @name = name
  @directory = directory
  self.class[name] = self
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



168
169
170
# File 'lib/dc.rb', line 168

def name
  @name
end

Class Method Details

.[](name) ⇒ Object



153
154
155
# File 'lib/dc.rb', line 153

def [] name
  all[name]
end

.[]=(name, image) ⇒ Object



157
158
159
# File 'lib/dc.rb', line 157

def []= name, image
  all[name] = image
end

.allObject



149
150
151
# File 'lib/dc.rb', line 149

def all
  @all ||= {}
end

Instance Method Details

#buildObject



174
175
176
177
178
179
180
181
# File 'lib/dc.rb', line 174

def build
  build_parent_image_if_available
  image = Docker::Image.build_from_dir @directory do |json|
    puts JSON.parse json
  end
  image.tag repo: @name
  image
end

#exist?Boolean

Returns:

  • (Boolean)


170
171
172
# File 'lib/dc.rb', line 170

def exist?
  Docker::Image.exist? @name
end

#tag(tag) ⇒ Object



183
184
185
# File 'lib/dc.rb', line 183

def tag tag
  Docker::Image.get(@name).tag repo: @name, tag: tag
end