Module: SettingsReader::Mixins::Path

Included in:
Backends::Abstract, Reader
Defined in:
lib/settings_reader/mixins/path.rb

Overview

Path related utility methods

Constant Summary collapse

PATH_SEPARATOR =
'/'.freeze

Instance Method Summary collapse

Instance Method Details

#decompose_path(path) ⇒ Object

Create list of parts from path using ‘/’ as separator. Remove empty/nil parts



15
16
17
18
# File 'lib/settings_reader/mixins/path.rb', line 15

def decompose_path(path)
  parts = path.to_s.split(PATH_SEPARATOR).compact
  parts.reject(&:empty?)
end

#generate_path(*parts) ⇒ Object

Create path from parts using ‘/’ as a separator



8
9
10
11
12
# File 'lib/settings_reader/mixins/path.rb', line 8

def generate_path(*parts)
  strings = parts.map(&:to_s)
  all_parts = strings.map { |s| s.split(PATH_SEPARATOR) }.flatten
  all_parts.reject(&:empty?).join('/')
end