Class: Sprinkle::Installers::Transfer
- Defined in:
- lib/sprinkle/installers/transfer.rb
Overview
If you pass the option :render => true, this tells transfer that the source file is an ERB template to be rendered locally before being transferred (you can declare variables in the package scope). When render is true, recursive is turned off.
package :nginx_conf do
nginx_port = 8080
transfer 'files/nginx.conf', '/etc/nginx.conf', :render => true
end
Finally, should you need to run commands before or after the file transfer (making directories or changing permissions), you can use the pre/post :install directives and they will be run.
Instance Attribute Summary collapse
-
#destination ⇒ Object
:nodoc:.
-
#source ⇒ Object
:nodoc:.
Attributes inherited from Installer
#delivery, #options, #package, #post, #pre
Attributes included from Configurable
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(parent, source, destination, options = {}, &block) ⇒ Transfer
constructor
:nodoc:.
- #install_commands ⇒ Object
-
#process(roles) ⇒ Object
:nodoc:.
- #render_template(template, context, prefix) ⇒ Object
- #render_template_file(path, context, prefix) ⇒ Object
Methods included from Configurable
#assert_delivery, #defaults, #method_missing, #option?
Constructor Details
#initialize(parent, source, destination, options = {}, &block) ⇒ Transfer
:nodoc:
88 89 90 91 92 |
# File 'lib/sprinkle/installers/transfer.rb', line 88 def initialize(parent, source, destination, ={}, &block) #:nodoc: super parent, , &block @source = source @destination = destination end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Sprinkle::Configurable
Instance Attribute Details
#destination ⇒ Object
:nodoc:
86 87 88 |
# File 'lib/sprinkle/installers/transfer.rb', line 86 def destination @destination end |
#source ⇒ Object
:nodoc:
86 87 88 |
# File 'lib/sprinkle/installers/transfer.rb', line 86 def source @source end |
Class Method Details
.render_template(template, context, prefix) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/sprinkle/installers/transfer.rb', line 98 def self.render_template(template, context, prefix) require 'tempfile' require 'erubis' begin eruby = Erubis::Eruby.new(template) output = eruby.result(context) rescue Object => e raise TemplateError.new(e, template, context) end final_tempfile = Tempfile.new(prefix) final_tempfile.print(output) final_tempfile.close final_tempfile end |
Instance Method Details
#install_commands ⇒ Object
94 95 96 |
# File 'lib/sprinkle/installers/transfer.rb', line 94 def install_commands nil end |
#process(roles) ⇒ Object
:nodoc:
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/sprinkle/installers/transfer.rb', line 125 def process(roles) #:nodoc: assert_delivery if logger.debug? logger.debug "transfer: #{@source} -> #{@destination} for roles: #{roles}\n" end unless Sprinkle::OPTIONS[:testing] pre = pre_commands(:install) unless pre.empty? sequence = pre; sequence = sequence.join('; ') if sequence.is_a? Array logger.info "#{@package.name} pre-transfer commands: #{sequence} for roles: #{roles}\n" @delivery.process @package.name, sequence, roles end recursive = @options[:recursive] if [:render] tempfile = render_template_file(@source, binding(), @package.name) sourcepath = tempfile.path logger.info "Rendering template #{@source} to temporary file #{sourcepath}" recursive = false else sourcepath = @source end logger.info "--> Transferring #{sourcepath} to #{@destination} for roles: #{roles}" @delivery.transfer(@package.name, sourcepath, @destination, roles, recursive) post = post_commands(:install) unless post.empty? sequence = post; sequence = sequence.join('; ') if sequence.is_a? Array logger.info "#{@package.name} post-transfer commands: #{sequence} for roles: #{roles}\n" @delivery.process @package.name, sequence, roles end end end |
#render_template(template, context, prefix) ⇒ Object
115 116 117 |
# File 'lib/sprinkle/installers/transfer.rb', line 115 def render_template(template, context, prefix) self.class.render_template(template, context, prefix) end |
#render_template_file(path, context, prefix) ⇒ Object
119 120 121 122 123 |
# File 'lib/sprinkle/installers/transfer.rb', line 119 def render_template_file(path, context, prefix) template = File.read(path) tempfile = render_template(template, binding(), @package.name) tempfile end |