Sha256: 21e9eaeea26d83ea7ee97faf8fbca8e378f4f08bf0551a9fad0101e6983d3ca0

Contents?: true

Size: 838 Bytes

Versions: 2

Compression:

Stored size: 838 Bytes

Contents

# frozen_string_literal: true

module Pups
  class FileCommand < Pups::Command
    attr_accessor :path, :contents, :params, :type, :chmod, :chown

    def self.from_hash(hash, params)
      command = new
      command.path = hash["path"]
      command.contents = hash["contents"]
      command.chmod = hash["chmod"]
      command.chown = hash["chown"]
      command.params = params

      command
    end

    def initialize
      @params = {}
      @type = :bash
    end

    attr_writer :params

    def run
      path = interpolate_params(@path)

      `mkdir -p #{File.dirname(path)}`
      File.open(path, "w") { |f| f.write(interpolate_params(contents)) }
      `chmod #{@chmod} #{path}` if @chmod
      `chown #{@chown} #{path}` if @chown
      Pups.log.info("File > #{path}  chmod: #{@chmod}  chown: #{@chown}")
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pups-1.2.1 lib/pups/file_command.rb
pups-1.2.0 lib/pups/file_command.rb