module Ellipses::Support::SanitizePath

Public Class Methods

extended(consumer) click to toggle source
Calls superclass method
# File lib/ellipses/support/sanitize_path.rb, line 78
def self.extended(consumer) # rubocop:disable Metrics/MethodLength
  super

  %i[file dir executable].each do |meth|
    klass = Sanitizer.const_get meth.capitalize

    consumer.define_singleton_method(meth) do |path, base: nil|
      klass.sanitize(path: path, base: base)
    rescue Sanitizer::Error
      nil
    end

    consumer.define_singleton_method("#{meth}!") do |path, error: nil, base: nil|
      klass.sanitize(path: path, base: base)
    rescue Sanitizer::Error => e
      error ? raise(error, e.message) : raise
    end
  end
end