Class: Deck::Container

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

Defined Under Namespace

Classes: Add, Archive, Cmd, Env, Expose, From, Name, Publish, Repository, Start, Tag, Variable, WorkDir

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeContainer

Returns a new instance of Container.



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/deck/container.rb', line 18

def initialize
  @information = {}
  @meta = {}
  @call_order = []
  self.class.constants.each do |sub|
    sub = self.class.const_get(sub).new
    if sub.class.meta?
      @meta[sub.class.register_name] = sub
    else
      @information[sub.class.register_name] = sub
    end
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object

Raises:

  • (NoMethodError)


50
51
52
53
54
# File 'lib/deck/container.rb', line 50

def method_missing(name, *args, &block)
  return handle_information(name, *args, &block) if @information.include? name.to_sym
  return handle_meta(name, *args, &block) if @meta.include? name.to_sym
  raise NoMethodError, "do not define such method : #{name.inspect}"
end

Instance Attribute Details

#metaObject (readonly)

Returns the value of attribute meta.



16
17
18
# File 'lib/deck/container.rb', line 16

def meta
  @meta
end

Instance Method Details

#build_commandObject



32
33
34
35
36
37
38
39
40
# File 'lib/deck/container.rb', line 32

def build_command
  dockerfile = ''
  @call_order.each do |info|
    command = @information[info].build_command(@information)
    dockerfile += "#{command}\n" unless command.nil?
    @information[info].next if @information[info].class.include? Deck::Repeatable
  end
  dockerfile
end

#image_nameObject



42
43
44
# File 'lib/deck/container.rb', line 42

def image_name
  "#{repository.to_s}/#{name.to_s}:#{tag.to_s}"
end

#run_commandObject



46
47
48
# File 'lib/deck/container.rb', line 46

def run_command
  "docker run #{image_name}"
end