Class: Hiiro::Paths::Symlink

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/hiiro/paths.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, hiiro = nil) ⇒ Symlink

Returns a new instance of Symlink.



43
44
45
46
# File 'lib/hiiro/paths.rb', line 43

def initialize(path, hiiro=nil)
  @hiiro = hiiro
  super(path)
end

Instance Attribute Details

#hiiroObject (readonly)

Returns the value of attribute hiiro.



41
42
43
# File 'lib/hiiro/paths.rb', line 41

def hiiro
  @hiiro
end

Instance Method Details

#abs_destObject



64
65
66
# File 'lib/hiiro/paths.rb', line 64

def abs_dest
  (path.dirname + dest).cleanpath
end

#destObject



52
53
54
# File 'lib/hiiro/paths.rb', line 52

def dest
  path.readlink
end

#dest_dirObject



76
77
78
# File 'lib/hiiro/paths.rb', line 76

def dest_dir
  path.directory? ? path : path.dirname
end

#dest_from_rootObject



68
69
70
# File 'lib/hiiro/paths.rb', line 68

def dest_from_root
  abs_dest.relative_path_from(root_path)
end

#dest_in_dir?(dir) ⇒ Boolean

Returns:

  • (Boolean)


80
81
82
83
84
85
# File 'lib/hiiro/paths.rb', line 80

def dest_in_dir?(dir)
  dir = Pathname.new(dir)

  relpath = dest.relative_path_from(dir)
  relpath.descend.first.to_s != '..'
end

#dest_relative_to(base_dir) ⇒ Object



72
73
74
# File 'lib/hiiro/paths.rb', line 72

def dest_relative_to(base_dir)
  abs_dest.relative_path_from(Pathname.new(base_dir))
end

#pathObject



48
49
50
# File 'lib/hiiro/paths.rb', line 48

def path
  @path ||= Pathname.new(__getobj__)
end

#rootObject



56
57
58
# File 'lib/hiiro/paths.rb', line 56

def root
  @root ||= hiiro&.git&.root || `git rev-parse --show-toplevel 2>/dev/null`.chomp
end

#root_pathObject



60
61
62
# File 'lib/hiiro/paths.rb', line 60

def root_path
  Pathname.new root
end