Class: TTY::Tree::Node Private

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/tty/tree/node.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A representation of tree node

Direct Known Subclasses

LeafNode

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, parent, prefix, level) ⇒ Node

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Node.



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/tty/tree/node.rb', line 35

def initialize(path, parent, prefix, level)
  if path.is_a? String
    # strip null bytes from the string to avoid throwing errors
    path = path.delete("\0")
  end

  @path = Pathname.new(path)
  @name   = @path.basename
  @parent = Pathname.new(parent)
  @prefix = prefix
  @level  = level
end

Instance Attribute Details

#levelObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The directory depth



24
25
26
# File 'lib/tty/tree/node.rb', line 24

def level
  @level
end

#nameObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The base name for the directory or file



15
16
17
# File 'lib/tty/tree/node.rb', line 15

def name
  @name
end

#parentObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The parent directory path



18
19
20
# File 'lib/tty/tree/node.rb', line 18

def parent
  @parent
end

#pathObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The current path



30
31
32
# File 'lib/tty/tree/node.rb', line 30

def path
  @path
end

#prefixObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The require path prefix



21
22
23
# File 'lib/tty/tree/node.rb', line 21

def prefix
  @prefix
end

#statObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The file stat



27
28
29
# File 'lib/tty/tree/node.rb', line 27

def stat
  @stat
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



70
71
72
# File 'lib/tty/tree/node.rb', line 70

def ==(other)
  other.is_a?(self.class) && other.state_attrs == state_attrs
end

#full_pathObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



48
49
50
51
52
# File 'lib/tty/tree/node.rb', line 48

def full_path
  return parent if name.to_s.empty?

  parent.join(name)
end

#hidden?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


58
59
60
# File 'lib/tty/tree/node.rb', line 58

def hidden?
  name.to_s.start_with?('.')
end

#leaf?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


62
63
64
# File 'lib/tty/tree/node.rb', line 62

def leaf?
  false
end

#root?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


54
55
56
# File 'lib/tty/tree/node.rb', line 54

def root?
  parent.to_s.empty?
end

#to_sObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



66
67
68
# File 'lib/tty/tree/node.rb', line 66

def to_s
  @name
end