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.
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
'.'.freeze
Instance Attribute Summary collapse
-
#separator ⇒ String
private
The separator is the character or pattern splitting paths.
Instance Method Summary collapse
-
#filter_components(components) ⇒ Object
private
Given path components, filters out unnecessary ones.
-
#join_path(components) ⇒ Object
private
Join path components with the ‘#separator`.
-
#normalize_path(path) ⇒ Object
private
Normalizes a String path so that there are no empty components, and it starts with a separator.
-
#parent_path(path) ⇒ Object
private
Get the parent path of the given path.
-
#path_components(path) ⇒ Object
private
Break path into components.
- #path_prefix ⇒ Object private
-
#path_prefix=(value) ⇒ Object
private
Assume any pathed access has this prefix.
-
#split_pattern ⇒ RegExp
private
The pattern to split paths at; based on ‘separator`.
Instance Attribute Details
#separator ⇒ String
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.
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.
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`.
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.
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.
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).
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_prefix ⇒ 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.
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.
25 26 27 |
# File 'lib/collapsium/support/path_components.rb', line 25 def path_prefix=(value) @path_prefix = normalize_path(value) end |
#split_pattern ⇒ RegExp
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`.
40 41 42 |
# File 'lib/collapsium/support/path_components.rb', line 40 def split_pattern /(?<!\\)#{Regexp.escape(separator)}/ end |