class Wright::Provider::Symlink

Symlink provider. Used as a provider for {Resource::Symlink}.

Public Instance Methods

create() click to toggle source

Creates or updates the symlink.

@return [void]

# File lib/wright/provider/symlink.rb, line 12
def create
  fail Errno::EEXIST, link_name_expanded if regular_file?

  symlink = symlink_to_s
  unless_uptodate(:create, "symlink already created: #{symlink}") do
    unless_dry_run("create symlink: #{symlink}") do
      Wright::Util::File.ln_sfn(link_to_expanded, link_name_expanded)
    end
  end
end
remove() click to toggle source

Removes the symlink.

@return [void]

# File lib/wright/provider/symlink.rb, line 26
def remove
  fail "'#{link_name_expanded}' is not a symlink" if regular_file?

  unless_uptodate(:remove, "symlink already removed: '#{link_name}'") do
    unless_dry_run("remove symlink: '#{link_name}'") do
      FileUtils.rm(link_name_expanded)
    end
  end
end

Private Instance Methods

regular_file?() click to toggle source
# File lib/wright/provider/symlink.rb, line 69
def regular_file?
  ::File.exist?(link_name_expanded) &&
    !::File.symlink?(link_name_expanded)
end
uptodate?(action) click to toggle source
# File lib/wright/provider/symlink.rb, line 59
def uptodate?(action)
  case action
  when :create
    ::File.symlink?(link_name_expanded) &&
      ::File.readlink(link_name_expanded) == link_to_expanded
  when :remove
    !::File.symlink?(link_name_expanded)
  end
end