Sha256: ac327daedefd64f5d5cdf6cc2f43e39e95383d1aba168aa8510cb1a96eda4ed9

Contents?: true

Size: 816 Bytes

Versions: 3

Compression:

Stored size: 816 Bytes

Contents

module ConfigCurator

  # A symlink is a symbolic link that should be created.
  # The {#destination_path} will be a link
  # that points to the {#source_path}.
  class Symlink < Unit

    # (see Unit#install)
    def install
      s = super
      return s unless s
      install_symlink
      true
    end

    # (see Unit#install?)
    def install?
      s = super
      return s unless s
      fail InstallFailed, "No source file specified." if source_path.nil?
      fail InstallFailed, "No destination specified." if destination_path.nil?
      true
    end

    private

    # Recursively creates the necessary directories and make the symlink.
    def install_symlink
      FileUtils.mkdir_p File.dirname(destination_path)
      FileUtils.symlink source_path, destination_path, force: true
    end
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
config_curator-0.1.1 lib/config_curator/units/symlink.rb
config_curator-0.1.0 lib/config_curator/units/symlink.rb
config_curator-0.0.2 lib/config_curator/units/symlink.rb