Sha256: f75912637197d2df9d9302ceac33455586ab3f7386d0384a4986c6e6f72e9f68

Contents?: true

Size: 1.05 KB

Versions: 2

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

require "pathname"
require "yaml"
require "fileutils"

module FeCoreExt::CoreExt
end

module FeCoreExt::CoreExt::Pathname
  def load_yaml
    return unless exist?
    YAML.load_file(self)
  end

  def glob(pattern, &block)
    Pathname.glob(join(pattern), &block)
  end

  def existence
    self if exist?
  end

  def touch(options = {})
    FileUtils.touch(@path, options)
  end

  def rm(options = {})
    FileUtils.rm(self, options)
  end

  def mkdir_p
    mkpath
    self
  end

  def copy(dest)
    FileUtils.cp(self, dest)
  end

  def require_relative
    Kernel.require_relative(self)
  end
end

module FeCoreExt::CoreExt::PathnameClassMethods
  def join(*args)
    new(File.join(*args))
  end

  def mktmpdir(prefix_suffix = nil, tmpdir = nil)
    if block_given?
      Dir.mktmpdir prefix_suffix, tmpdir do |dir|
        yield new(dir)
      end
    else
      new(Dir.mktmpdir(prefix_suffix, tmpdir))
    end
  end
end

class Pathname
  extend FeCoreExt::CoreExt::PathnameClassMethods
  include FeCoreExt::CoreExt::Pathname
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fe_core_ext-0.30.0 lib/fe_core_ext/core_ext/pathname.rb
fe_core_ext-0.29.1 lib/fe_core_ext/core_ext/pathname.rb