Class: Resource::File

Inherits:
Base
  • Object
show all
Defined in:
lib/resource/file.rb

Instance Method Summary collapse

Methods inherited from Base

inherited, #not_if, #set_base_defaults, #should_skip?, #unix_mode

Methods included from ClassAttr

included

Methods included from BlockAttr

included

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

#runObject

Compile any given string into a file remotely!

  1. try to run everytime

  2. if file exists and current string checksum matches the old one skip it!

  3. 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