Sha256: 73ec0e784b5c6de9c23578b869bdf8747fb26b1f223661f2d79f8c28b19fa995

Contents?: true

Size: 1.13 KB

Versions: 1

Compression:

Stored size: 1.13 KB

Contents

module BerkeleyLibrary
  module Util
    # TODO: Move this to `berkeley_library-util`
    module Files
      class << self
        include Files
      end

      def file_exists?(path)
        (path.respond_to?(:exist?) && path.exist?) ||
          (path.respond_to?(:to_str) && File.exist?(path))
      end

      def parent_exists?(path)
        path.respond_to?(:parent) && path.parent.exist? ||
          path.respond_to?(:to_str) && Pathname.new(path).parent.exist?
      end

      # Returns true if `obj` is close enough to an IO object for Nokogiri
      # to parse as one.
      #
      # @param obj [Object] the object that might be an IO
      # @see https://github.com/sparklemotion/nokogiri/blob/v1.11.1/lib/nokogiri/xml/sax/parser.rb#L81 Nokogiri::XML::SAX::Parser#parse
      def reader_like?(obj)
        obj.respond_to?(:read) && obj.respond_to?(:close)
      end

      # Returns true if `obj` is close enough to an IO object for Nokogiri
      # to write to.
      #
      # @param obj [Object] the object that might be an IO
      def writer_like?(obj)
        obj.respond_to?(:write) && obj.respond_to?(:close)
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
berkeley_library-tind-0.6.0 lib/berkeley_library/util/files.rb