Module: Ellipses::Support::SanitizePath

Included in:
Ellipses::Support
Defined in:
lib/ellipses/support/sanitize_path.rb

Class Method Summary collapse

Class Method Details

.extended(consumer) ⇒ Object

rubocop:disable Metrics/MethodLength



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# 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