Class: Resource::File
Instance Method Summary collapse
-
#initialize(target, &block) ⇒ File
constructor
A new instance of File.
-
#run ⇒ Object
Compile any given string into a file remotely!.
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) ⇒ File
Returns a new instance of File.
7 8 9 10 11 |
# File 'lib/resource/file.rb', line 7 def initialize target, &block set_base_defaults @target = target self.instance_eval(&block) end |
Instance Method Details
#run ⇒ Object
Compile any given string into a file remotely!
-
try to run everytime
-
if file exists and current string checksum matches the old one skip it!
-
otherwise just re-compile the file!
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/resource/file.rb', line 20 def run Execution.block 'Creating a custom file', @target, 'root' do |b| b.always_run true b.run "mkdir -p #{::File.dirname(@target)}" ::File.open(@target, 'w+') { |file| file.write @content } b.run "chown #{@owner}:#{@owner} #{::File.dirname(@target)}" b.run "chown #{@owner}:#{@owner} #{@target}" b.run "chmod #{unix_mode} #{@target}" end end |