Module: LibPath::Form::Unix::LibPath_Form_Unix_Methods

Included in:
LibPath::Form::Unix, LibPath::Form::Unix
Defined in:
lib/libpath/form/unix.rb

Overview

Module defining instance functions that will be included and extended into any class or module including/extending module LibPath::Form::Unix

Instance Method Summary collapse

Instance Method Details

#classify_path(path) ⇒ Object

Classifies a path

Return

One of :absolute, :homed, :relative, for any paths that match precisely those classifications, or nil if the path is empty



70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/libpath/form/unix.rb', line 70

def classify_path path

  Diagnostics.check_string_parameter(path, "path") if $DEBUG

  return nil if path.nil? || path.empty?

  return :homed if path_is_homed? path

  return :absolute if path_is_absolute? path

  :relative
end

#name_is_malformed?(name, **options) ⇒ Boolean

Evaluates whether the given name is malformed

Signature

  • Options:

  • :reject_path_name_separators

    (boolean) Reject the path

    separator character(s): +'/'+
    
  • :reject_path_separators

    (boolean) Reject the path separator

    character(s): +':'+
    
  • :reject_shell_characters

    (boolean) Reject the shell

    character(s): +'*'+, +'?'+, +'|'+
    

Returns:

  • (Boolean)


94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/libpath/form/unix.rb', line 94

def name_is_malformed? name, **options

  _Constants = ::LibPath::Constants::Unix

  if name

    if options[:reject_path_name_separators]

      return true if name =~ _Constants::InvalidCharacters::PathNameSeparators::RE
    end

    if options[:reject_path_separators]

      return true if name =~ _Constants::InvalidCharacters::PathSeparators::RE
    end

    if options[:reject_shell_characters]

      return true if name =~ _Constants::InvalidCharacters::Shell::RE
    end

    return true if name =~ _Constants::InvalidCharacters::Innate::RE

    false
  else

    true
  end
end

#path_is_absolute?(path) ⇒ Boolean

Evaluates whether the given path is absolute, which means it is either rooted (begins with ‘/’) or is homed (is ‘~’ or begins with ‘~/’)

Signature

  • Parameters:

    • path

      (String) The path to be evaluated. May not be nil

Returns:

  • (Boolean)


131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/libpath/form/unix.rb', line 131

def path_is_absolute? path

  Diagnostics.check_string_parameter(path, "path") if $DEBUG

  case path[0]
  when '/'

    true
  when '~'

    1 == path.size || '/' == path[1]
  else

    false
  end
end

#path_is_homed?(path) ⇒ Boolean

Evaluates whether the given path is homed, which means it is ‘~’ or begins with ‘~/’

Signature

  • Parameters:

    • path

      (String) The path to be evaluated. May not be nil

Returns:

  • (Boolean)


155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/libpath/form/unix.rb', line 155

def path_is_homed? path

  Diagnostics.check_string_parameter(path, "path") if $DEBUG

  return false unless '~' == path[0]

  if path.size > 1

    return '/' == path[1]
  end

  true
end

#path_is_rooted?(path) ⇒ Boolean

Evalutes whether the given path is rooted, which means it begins with ‘/’

Signature

  • Parameters:

    • path

      (String) The path to be evaluated. May not be nil

Returns:

  • (Boolean)


176
177
178
179
180
181
# File 'lib/libpath/form/unix.rb', line 176

def path_is_rooted? path

  Diagnostics.check_string_parameter(path, "path") if $DEBUG

  '/' == path[0]
end