Class: Cane::File

Inherits:
Object
  • Object
show all
Defined in:
lib/cane/file.rb

Overview

An interface for interacting with files that ensures encoding is handled in a consistent manner.

Class Method Summary collapse

Class Method Details

.case_insensitive_glob(glob) ⇒ Object



25
26
27
# File 'lib/cane/file.rb', line 25

def case_insensitive_glob(glob)
  Dir.glob(glob, ::File::FNM_CASEFOLD)
end

.contents(path) ⇒ Object



13
14
15
# File 'lib/cane/file.rb', line 13

def contents(path)
  open(path).read
end

.exists?(path) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/cane/file.rb', line 21

def exists?(path)
  ::File.exists?(path)
end

.iterator(path) ⇒ Object



9
10
11
# File 'lib/cane/file.rb', line 9

def iterator(path)
  EncodingAwareIterator.new(open(path).each_line)
end

.open(path) ⇒ Object



17
18
19
# File 'lib/cane/file.rb', line 17

def open(path)
  ::File.open(path, 'r:utf-8')
end