Top Level Namespace

Defined Under Namespace

Classes: Fsorg

Constant Summary collapse

PERMISSIONS_PATTERN =
/[ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=]?[0-7]+/

Instance Method Summary collapse

Instance Method Details

#capture_outputObject



451
452
453
454
455
456
457
458
459
460
461
# File 'lib/fsorg.rb', line 451

def capture_output
  old_stdout = $stdout
  old_stderr = $stderr
  $stdout = StringIO.new
  $stderr = StringIO.new
  yield
  [$stdout.string, $stderr.string]
ensure
  $stdout = old_stdout
  $stderr = old_stderr
end

#d(thing) ⇒ Object



10
11
12
13
# File 'lib/fsorg.rb', line 10

def d(thing)
  p thing
  thing
end

#dedent(text) ⇒ Object

rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity



422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
# File 'lib/fsorg.rb', line 422

def dedent(text) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
  lines = text.split "\n"
  return text if lines.empty?

  indents = lines.map do |line|
    if line =~ /\S/
      line.start_with?(" ") ? line.match(/^ +/).offset(0)[1] : 0
    end
  end
  indents.compact!
  if indents.empty?
    # No lines had any non-whitespace characters.
    return ([""] * lines.size).join "\n"
  end

  min_indent = indents.min
  return text if min_indent.zero?

  lines.map { |line| line =~ /\S/ ? line.gsub(/^ {#{min_indent}}/, "") : line }.join "\n"
end

#ensure_final_newline(text) ⇒ Object



443
444
445
446
447
448
449
# File 'lib/fsorg.rb', line 443

def ensure_final_newline(text)
  if text.end_with? "\n"
    text
  else
    "#{text}\n"
  end
end