Class: Hiiro::Paths
- Inherits:
-
Object
- Object
- Hiiro::Paths
- Defined in:
- lib/hiiro/paths.rb
Defined Under Namespace
Classes: Symlink
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#hiiro ⇒ Object
readonly
Returns the value of attribute hiiro.
Class Method Summary collapse
-
.unique_path(dir, base_name, ext: '.md') ⇒ Object
Returns [full_path, unique_name] — appends -2, -3, etc.
Instance Method Summary collapse
- #from_base(file) ⇒ Object
-
#initialize(base = Dir.pwd, hiiro: nil) ⇒ Paths
constructor
A new instance of Paths.
- #symlinks_in(path) ⇒ Object
Constructor Details
#initialize(base = Dir.pwd, hiiro: nil) ⇒ Paths
Returns a new instance of Paths.
10 11 12 13 |
# File 'lib/hiiro/paths.rb', line 10 def initialize(base=Dir.pwd, hiiro: nil) @base = Pathname.new base @hiiro = hiiro end |
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
8 9 10 |
# File 'lib/hiiro/paths.rb', line 8 def base @base end |
#hiiro ⇒ Object (readonly)
Returns the value of attribute hiiro.
8 9 10 |
# File 'lib/hiiro/paths.rb', line 8 def hiiro @hiiro end |
Class Method Details
.unique_path(dir, base_name, ext: '.md') ⇒ Object
Returns [full_path, unique_name] — appends -2, -3, etc. if a file with the same base_name already exists in dir.
30 31 32 33 34 35 36 37 38 |
# File 'lib/hiiro/paths.rb', line 30 def self.unique_path(dir, base_name, ext: '.md') name = base_name counter = 1 while File.exist?(File.join(dir, "#{name}#{ext}")) counter += 1 name = "#{base_name}-#{counter}" end [File.join(dir, "#{name}#{ext}"), name] end |
Instance Method Details
#from_base(file) ⇒ Object
15 16 17 18 |
# File 'lib/hiiro/paths.rb', line 15 def from_base(file) path = Pathname.new(file) path.relative_path_from(base) end |