Sha256: 8a74424973d979961f058832f53aa88f9510a7e56db916ebf2d18d0ecb698640

Contents?: true

Size: 813 Bytes

Versions: 5

Compression:

Stored size: 813 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

5 entries across 5 versions & 1 rubygems

Version Path
config_curator-0.2.4 lib/config_curator/units/symlink.rb
config_curator-0.2.3 lib/config_curator/units/symlink.rb
config_curator-0.2.2 lib/config_curator/units/symlink.rb
config_curator-0.2.1 lib/config_curator/units/symlink.rb
config_curator-0.2.0 lib/config_curator/units/symlink.rb