Class: KFileset::PathEntry

Inherits:
Pathname
  • Object
show all
Includes:
KLog::Logging
Defined in:
lib/k_fileset/path_entry.rb

Overview

PathEntry is a (RUBY) Pathname object with some extra properties

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ PathEntry

_path_name,



15
16
17
18
19
20
21
22
23
24
# File 'lib/k_fileset/path_entry.rb', line 15

def initialize(path)
  super(path)
  # @key = realpath.to_s
  # @key = File.join(@key, '.') if pathname.ends_with?('.')
  # puts @key
  # @path_name = path_name
  @working_directory = Dir.getwd
  # @pathname = pathname
  # debug
end

Instance Attribute Details

#working_directoryObject (readonly)

unique absolute path name e.g.(/abc, /abc/.) attr_reader :key attr_reader :path_name # Pathname



10
11
12
# File 'lib/k_fileset/path_entry.rb', line 10

def working_directory
  @working_directory
end

Instance Method Details

#debugObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/k_fileset/path_entry.rb', line 55

def debug
  log.kv 'key', key
  log.kv 'working_directory', working_directory
  log.kv 'safe_realpath', safe_realpath
  log.kv 'to_path', to_path
  log.kv 'cleanpath', cleanpath
  log.line

  # puts "expand_path   : #{self.expand_path.to_s}"
  # puts "realdirpath   : #{self.realdirpath.to_s}"
  # puts "realpath      : #{self.realpath.to_s}"
  # puts "extname       : #{self.extname.to_s}"
  # puts "basename      : #{self.basename.to_s}"
  # puts "dirname       : #{self.dirname.to_s}"
  # puts "to_path       : #{self.to_path.to_s}"
  # puts "parent        : #{self.parent.to_s}"
  # log.line
  # log.kv 'directory?', directory?
  # log.kv 'root?', root?
  # log.kv 'absolute?', absolute?
  # log.kv 'relative?', relative?
  # log.kv 'exist?', exist?
  # log.kv 'file?', file?
  # log.kv 'size?', size?
  # log.kv 'ftype', ftype
  # log.kv 'empty?', empty?
  # log.kv 'readable?', readable?
  # log.kv 'birthtime', birthtime
  # log.kv 'expand_path', expand_path
  # log.kv 'realdirpath', realdirpath
  # log.kv 'realpath', realpath
  # log.kv 'extname', extname
  # log.kv 'basename', basename
  # log.kv 'dirname', dirname
  # log.kv 'to_path', to_path
  # log.kv 'size', size
end

#keyObject



26
27
28
29
30
31
32
33
34
# File 'lib/k_fileset/path_entry.rb', line 26

def key
  return @key if defined? @key

  @key = begin
    key = safe_realpath
    key = File.join(key, '.') if basename.to_s == '.' # if pathname.ends_with?('.')
    key
  end
end

#safe_realpathObject

Friendly path will return absolute path if the folder/file exists. If the file/folder does NOT exist then the the value of the underlying @path is used and this is likely to be a relative path



46
47
48
49
# File 'lib/k_fileset/path_entry.rb', line 46

def safe_realpath
  # Cannot use @path because that instance variable is already used on Pathname
  @safe_realpath ||= exist? ? realpath.to_s : File.expand_path(self)
end

#uriObject



51
52
53
# File 'lib/k_fileset/path_entry.rb', line 51

def uri
  URI::File.build(host: nil, path: safe_realpath)
end