Class: Kdeploy::Template
- Inherits:
-
Object
- Object
- Kdeploy::Template
- Defined in:
- lib/kdeploy/template.rb
Class Method Summary collapse
- .render(template_path, variables = {}) ⇒ Object
- .render_and_upload(executor, template_path, destination, variables = {}) ⇒ Object
Class Method Details
.render(template_path, variables = {}) ⇒ Object
8 9 10 11 12 |
# File 'lib/kdeploy/template.rb', line 8 def self.render(template_path, variables = {}) template_content = File.read(template_path) context = OpenStruct.new(variables) ERB.new(template_content).result(context.instance_eval { binding }) end |
.render_and_upload(executor, template_path, destination, variables = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/kdeploy/template.rb', line 14 def self.render_and_upload(executor, template_path, destination, variables = {}) rendered_content = render(template_path, variables) # 创建临时文件 temp_file = Tempfile.new('kdeploy') begin temp_file.write(rendered_content) temp_file.close # 上传渲染后的文件 executor.upload(temp_file.path, destination) ensure temp_file.unlink end end |