Class: Dockerfile::Base

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

Overview

Provides shared behavior for dockerfile template classes.

Direct Known Subclasses

NodeJS, Ruby

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



7
8
9
# File 'lib/dockerfile/base.rb', line 7

def initialize
  @template = []
end

Instance Attribute Details

#commandObject

Returns the value of attribute command.



5
6
7
# File 'lib/dockerfile/base.rb', line 5

def command
  @command
end

#templateObject (readonly)

Returns the value of attribute template.



4
5
6
# File 'lib/dockerfile/base.rb', line 4

def template
  @template
end

Instance Method Details

#renderObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/dockerfile/base.rb', line 15

def render
  required_attributes.each do |attr|
    raise(MissingPropertyError, "Must populate #{attr}") if send(attr).nil?
  end

  unrendered_output = template.reduce("") do |out, (command, string)|
    out << command.to_s.upcase << " " << string << "\n"
  end

  ERB.new(unrendered_output).result(binding)
end

#required_attributesObject



11
12
13
# File 'lib/dockerfile/base.rb', line 11

def required_attributes
  [:command]
end

#run(command, before: [:cmd]) ⇒ Object



27
28
29
# File 'lib/dockerfile/base.rb', line 27

def run(command, before: [:cmd])
  template.insert(do_before(before), [:run, command])
end