Class: Dockerun::Template::TemplateWriter
- Inherits:
-
Object
- Object
- Dockerun::Template::TemplateWriter
- Includes:
- UserInfo
- Defined in:
- lib/dockerun/template/template_writer.rb
Direct Known Subclasses
Defined Under Namespace
Classes: TemplateNotFound
Instance Attribute Summary collapse
-
#image ⇒ Object
Returns the value of attribute image.
-
#image_base ⇒ Object
Returns the value of attribute image_base.
-
#maintainer ⇒ Object
Returns the value of attribute maintainer.
- #user_configurables ⇒ Object
-
#user_group_id ⇒ Object
Returns the value of attribute user_group_id.
-
#user_group_name ⇒ Object
Returns the value of attribute user_group_name.
-
#user_id ⇒ Object
Returns the value of attribute user_id.
-
#user_login ⇒ Object
Returns the value of attribute user_login.
Class Method Summary collapse
Instance Method Summary collapse
- #compile(&block) ⇒ Object
-
#initialize(template = :general) ⇒ TemplateWriter
constructor
A new instance of TemplateWriter.
Methods included from UserInfo
Constructor Details
#initialize(template = :general) ⇒ TemplateWriter
Returns a new instance of TemplateWriter.
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/dockerun/template/template_writer.rb', line 26 def initialize(template = :general) @template = template @image = "<Replace me>" user = user_info group = group_info @maintainer = user[:login] @user_group_id = group[:group_id] @user_group_name = group[:group_name] @user_id = user[:user_id] @user_login = user[:login] @image_base = :ubuntu end |
Instance Attribute Details
#image ⇒ Object
Returns the value of attribute image.
14 15 16 |
# File 'lib/dockerun/template/template_writer.rb', line 14 def image @image end |
#image_base ⇒ Object
Returns the value of attribute image_base.
14 15 16 |
# File 'lib/dockerun/template/template_writer.rb', line 14 def image_base @image_base end |
#maintainer ⇒ Object
Returns the value of attribute maintainer.
14 15 16 |
# File 'lib/dockerun/template/template_writer.rb', line 14 def maintainer @maintainer end |
#user_configurables ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/dockerun/template/template_writer.rb', line 39 def user_configurables fields = { image: { desc: "Image name of the docker based on", required: true }, image_base: { desc: "Image is based on which OS? Assumption with be on Debian based. ", default: :ubuntu }, maintainer: { desc: "Maintainer of the Dockerfile", default: @maintainer } } if TR::RTUtils.on_linux? f2 = { user_group_id: { desc: "User group ID that shall be created in docker. Default to current running user's ID", default: @user_group_id.to_s }, user_group_name: { desc: "User group name that shall be created in docker. Default to current running user's group", default: @user_group_name }, user_id: { desc: "User ID that shall be created in docker. Default to current running user ID", default: @user_id.to_s }, user_login: { desc: "User login name that shall be created in docker. Default to current running user's login", default: @user_login } } fields.merge!(f2) end fields end |
#user_group_id ⇒ Object
Returns the value of attribute user_group_id.
14 15 16 |
# File 'lib/dockerun/template/template_writer.rb', line 14 def user_group_id @user_group_id end |
#user_group_name ⇒ Object
Returns the value of attribute user_group_name.
14 15 16 |
# File 'lib/dockerun/template/template_writer.rb', line 14 def user_group_name @user_group_name end |
#user_id ⇒ Object
Returns the value of attribute user_id.
14 15 16 |
# File 'lib/dockerun/template/template_writer.rb', line 14 def user_id @user_id end |
#user_login ⇒ Object
Returns the value of attribute user_login.
14 15 16 |
# File 'lib/dockerun/template/template_writer.rb', line 14 def user_login @user_login end |
Class Method Details
.instance(template) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/dockerun/template/template_writer.rb', line 17 def self.instance(template) tmp = template.to_s.downcase if tmp =~ /jruby/ JrubyTemplateWriter.new else TemplateWriter.new end end |
Instance Method Details
#compile(&block) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/dockerun/template/template_writer.rb', line 58 def compile(&block) if not_empty?(@user_configurables) @user_configurables.each do |k,v| begin self.send("#{k}=", v) rescue Exception => ex STDERR.puts "Setting value exception : #{ex}" end end end tmp = find_template cont = nil File.open(tmp,"r") do |f| cont = f.read end b = binding res = ERB.new(cont) res.result(b) end |