Class: Dockerfile::Base
- Inherits:
-
Object
- Object
- Dockerfile::Base
- Defined in:
- lib/dockerfile/base.rb
Overview
Provides shared behavior for dockerfile template classes.
Instance Attribute Summary collapse
-
#command ⇒ Object
Returns the value of attribute command.
-
#template ⇒ Object
readonly
Returns the value of attribute template.
Instance Method Summary collapse
-
#initialize ⇒ Base
constructor
A new instance of Base.
- #render ⇒ Object
- #required_attributes ⇒ Object
- #run(command, before: [:cmd]) ⇒ Object
Constructor Details
#initialize ⇒ Base
Returns a new instance of Base.
7 8 9 |
# File 'lib/dockerfile/base.rb', line 7 def initialize @template = [] end |
Instance Attribute Details
#command ⇒ Object
Returns the value of attribute command.
5 6 7 |
# File 'lib/dockerfile/base.rb', line 5 def command @command end |
#template ⇒ Object (readonly)
Returns the value of attribute template.
4 5 6 |
# File 'lib/dockerfile/base.rb', line 4 def template @template end |
Instance Method Details
#render ⇒ Object
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_attributes ⇒ Object
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 |