Module: Crystal::FilesHelper

Defined in:
lib/crystal/environment/files_helper.rb

Instance Method Summary collapse

Instance Method Details

#directoriesObject



3
4
5
# File 'lib/crystal/environment/files_helper.rb', line 3

def directories
  $LOAD_PATH
end

#file_exist?(path) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/crystal/environment/files_helper.rb', line 7

def file_exist? path
  find_files(path).size > 0
end

#find_file(fname) ⇒ Object



20
21
22
23
24
25
# File 'lib/crystal/environment/files_helper.rb', line 20

def find_file fname
  files = find_files(fname)
  raise "File '#{fname}' not found!" if files.size == 0
  raise "Found multiple files for '#{fname}'" if files.size > 1
  files.first
end

#find_file_by_pattern(pattern) ⇒ Object



34
35
36
37
38
39
# File 'lib/crystal/environment/files_helper.rb', line 34

def find_file_by_pattern pattern
  files = find_files_by_pattern(pattern)
  raise "File '#{pattern}' not found!" if files.size == 0
  raise "Found multiple files for '#{pattern}'" if files.size > 1
  files.first
end

#find_files_by_pattern_without_cache(pattern, directories = nil) ⇒ Object Also known as: find_files_by_pattern



27
28
29
30
31
# File 'lib/crystal/environment/files_helper.rb', line 27

def find_files_by_pattern_without_cache pattern, directories = nil
  directories ||= self.directories
  patterns = directories.to_a.collect{|d| "#{d}#{pattern}"}
  Dir.glob patterns
end

#find_files_without_cache(fname, directories = nil) ⇒ Object

find_files



12
13
14
15
16
17
# File 'lib/crystal/environment/files_helper.rb', line 12

def find_files_without_cache fname, directories = nil
  fname.must =~ /\//
  directories ||= self.directories
  files = directories.collect{|dir| "#{dir}#{fname}"}
  files.select{|f| File.exist? f}
end