Class: Hiiro::Paths::Symlink
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Hiiro::Paths::Symlink
- Defined in:
- lib/hiiro/paths.rb
Instance Attribute Summary collapse
-
#hiiro ⇒ Object
readonly
Returns the value of attribute hiiro.
Instance Method Summary collapse
- #abs_dest ⇒ Object
- #dest ⇒ Object
- #dest_dir ⇒ Object
- #dest_from_root ⇒ Object
- #dest_in_dir?(dir) ⇒ Boolean
- #dest_relative_to(base_dir) ⇒ Object
-
#initialize(path, hiiro = nil) ⇒ Symlink
constructor
A new instance of Symlink.
- #path ⇒ Object
- #root ⇒ Object
- #root_path ⇒ Object
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
#hiiro ⇒ Object (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_dest ⇒ Object
64 65 66 |
# File 'lib/hiiro/paths.rb', line 64 def abs_dest (path.dirname + dest).cleanpath end |
#dest ⇒ Object
52 53 54 |
# File 'lib/hiiro/paths.rb', line 52 def dest path.readlink end |
#dest_dir ⇒ Object
76 77 78 |
# File 'lib/hiiro/paths.rb', line 76 def dest_dir path.directory? ? path : path.dirname end |
#dest_from_root ⇒ Object
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
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 |
#path ⇒ Object
48 49 50 |
# File 'lib/hiiro/paths.rb', line 48 def path @path ||= Pathname.new(__getobj__) end |
#root ⇒ Object
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_path ⇒ Object
60 61 62 |
# File 'lib/hiiro/paths.rb', line 60 def root_path Pathname.new root end |