Sha256: 077e871ba779cdc5891813a3605d6e79e3e349489ff920b15a77f1d109a37c1c

Contents?: true

Size: 882 Bytes

Versions: 4

Compression:

Stored size: 882 Bytes

Contents

module Resource

  class File < Base

    block_attr :content, :owner, :group, :mode, :action, :target

    def initialize target, &block
      set_base_defaults
      @target = target
      self.instance_eval(&block)
    end

    # 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!
    #
    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

  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
atesta-0.0.4 lib/resource/file.rb
atesta-0.0.3 lib/resource/file.rb
atesta-0.0.2 lib/resource/file.rb
atesta-0.0.1 lib/resource/file.rb