Module: BerkeleyLibrary::Util::Files

Extended by:
Files
Included in:
Files
Defined in:
lib/berkeley_library/util/files.rb

Instance Method Summary collapse

Instance Method Details

#file_exists?(path) ⇒ Boolean



8
9
10
11
# File 'lib/berkeley_library/util/files.rb', line 8

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

#parent_exists?(path) ⇒ Boolean



13
14
15
16
# File 'lib/berkeley_library/util/files.rb', line 13

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

#reader_like?(obj) ⇒ Boolean

Returns true if obj is close enough to an IO object for Nokogiri to parse as one.



23
24
25
# File 'lib/berkeley_library/util/files.rb', line 23

def reader_like?(obj)
  obj.respond_to?(:read) && obj.respond_to?(:close)
end

#writer_like?(obj) ⇒ Boolean

Returns true if obj is close enough to an IO object for Nokogiri to write to.



31
32
33
# File 'lib/berkeley_library/util/files.rb', line 31

def writer_like?(obj)
  obj.respond_to?(:write) && obj.respond_to?(:close)
end