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
link_name()
click to toggle source
# File lib/wright/provider/symlink.rb, line 38 def link_name resource.name end
link_name_expanded()
click to toggle source
# File lib/wright/provider/symlink.rb, line 51 def link_name_expanded Wright::Util::File.expand_tilde_path(link_name) end
link_to()
click to toggle source
# File lib/wright/provider/symlink.rb, line 42 def link_to resource.to end
link_to_expanded()
click to toggle source
# File lib/wright/provider/symlink.rb, line 46 def link_to_expanded return nil if link_to.nil? Wright::Util::File.expand_tilde_path(link_to) end
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
symlink_to_s()
click to toggle source
# File lib/wright/provider/symlink.rb, line 55 def symlink_to_s "'#{link_name}' -> '#{link_to}'" 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