Module: Collapsium::Support::PathComponents Private

Included in:
PathedAccess
Defined in:
lib/collapsium/support/path_components.rb

Overview

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

Defines functions for path prefixes and components. This is mainly used by PathedAccess, but it helps keeping everything separate so that ViralCapabilities can also apply it to Arrays.

API:

  • private

Constant Summary collapse

DEFAULT_SEPARATOR =

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

Default path separator

API:

  • private

'.'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#separatorString

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 the separator is the character or pattern splitting paths.

Returns:

  • the separator is the character or pattern splitting paths.

API:

  • private



45
46
47
48
# File 'lib/collapsium/support/path_components.rb', line 45

def separator
  @separator ||= DEFAULT_SEPARATOR
  return @separator
end

Instance Method Details

#filter_components(components) ⇒ Object

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.

Given path components, filters out unnecessary ones.

API:

  • private



61
62
63
# File 'lib/collapsium/support/path_components.rb', line 61

def filter_components(components)
  return components.select { |c| not c.nil? and not c.empty? }
end

#join_path(components) ⇒ Object

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.

Join path components with the #separator.

API:

  • private



67
68
69
# File 'lib/collapsium/support/path_components.rb', line 67

def join_path(components)
  return components.join(separator)
end

#normalize_path(path) ⇒ Object

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.

Normalizes a String path so that there are no empty components, and it starts with a separator.

API:

  • private



81
82
83
84
85
86
87
88
89
# File 'lib/collapsium/support/path_components.rb', line 81

def normalize_path(path)
  components = []
  if path.respond_to?(:split) # likely a String
    components = path_components(path)
  elsif path.respond_to?(:join) # likely an Array
    components = filter_components(path)
  end
  return separator + join_path(components)
end

#parent_path(path) ⇒ Object

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.

Get the parent path of the given path.

API:

  • private



73
74
75
76
# File 'lib/collapsium/support/path_components.rb', line 73

def parent_path(path)
  components = path_components(normalize_path(path))
  return normalize_path(components.slice(0, components.length - 1))
end

#path_components(path) ⇒ Object

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.

Break path into components. Expects a String path separated by the #separator, and returns the path split into components (an Array of String).

API:

  • private



55
56
57
# File 'lib/collapsium/support/path_components.rb', line 55

def path_components(path)
  return filter_components(path.split(split_pattern))
end

#path_prefixObject

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.

API:

  • private



29
30
31
32
# File 'lib/collapsium/support/path_components.rb', line 29

def path_prefix
  @path_prefix ||= separator
  return @path_prefix
end

#path_prefix=(value) ⇒ Object

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.

Assume any pathed access has this prefix.

API:

  • private



25
26
27
# File 'lib/collapsium/support/path_components.rb', line 25

def path_prefix=(value)
  @path_prefix = normalize_path(value)
end

#split_patternRegExp

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 the pattern to split paths at; based on separator.

Returns:

  • the pattern to split paths at; based on separator

API:

  • private



40
41
42
# File 'lib/collapsium/support/path_components.rb', line 40

def split_pattern
  /(?<!\\)#{Regexp.escape(separator)}/
end