Sha256: 6ff993e66ef4a718fb0514288812bf6964acf85b0ebda2538d717698dda5eeb4

Contents?: true

Size: 1.2 KB

Versions: 3

Compression:

Stored size: 1.2 KB

Contents

module Crystal
  module FilesHelper
    def directories
      $LOAD_PATH
    end
    
    def file_exist? path
      find_files(path).size > 0
    end
            
    # find_files    
    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
    cache_method_with_params_in_production :find_files    
    
    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
    
    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
    alias_method :find_files_by_pattern, :find_files_by_pattern_without_cache
    
    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
  end
end
  

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
crystal-0.0.13 lib/crystal/environment/files_helper.rb
crystal-0.0.12 lib/crystal/environment/files_helper.rb
crystal_ext-0.0.11 lib/crystal/environment/files_helper.rb