Class: Resource::RemoteFile
Instance Method Summary collapse
- #content ⇒ Object
-
#initialize(target, &block) ⇒ RemoteFile
constructor
Install a static local file into a remote server.
- #run ⇒ Object
Methods inherited from Base
inherited, #not_if, #set_base_defaults, #should_skip?, #unix_mode
Methods included from ClassAttr
Methods included from BlockAttr
Constructor Details
#initialize(target, &block) ⇒ RemoteFile
Install a static local file into a remote server.
8 9 10 11 12 13 |
# File 'lib/resource/remote_file.rb', line 8 def initialize target, &block set_base_defaults @pattern = 'cookbooks/*/files/default/' @target = target self.instance_eval(&block) end |
Instance Method Details
#content ⇒ Object
15 16 17 18 19 20 |
# File 'lib/resource/remote_file.rb', line 15 def content (Dir[@pattern + '*'] + Dir[@pattern + '*.*']).each do |file| return ::File.read(file) if file.include? @source end 'Resource was not found' end |
#run ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/resource/remote_file.rb', line 22 def run Execution.block 'Creating a remote file', @target, @owner do |b| if ::File.exist? @target sums_equal = MD5.hexdigest(::File.read(@target)) == MD5.hexdigest(content) else sums_equal = false @always_run = true end if sums_equal Output.warn 'Skipping', 'checksum comparison matches' else Output.warn 'Generating file with ruby', @target ::File.open(@target, 'w+') { |file| file.write content } b.always_run @always_run b.run "chown #{@owner}:#{@group} #{@target}" b.run "chmod #{unix_mode} #{@target}" end end end |