Sha256: 896fa6ab4acb17f5956a84d85b045c6a7348f4e32eb9cf449da8b23521b366e3

Contents?: true

Size: 1.44 KB

Versions: 26

Compression:

Stored size: 1.44 KB

Contents

require 'fileutils'
require 'constants' # for Verbosity enumeration

class FileFinderHelper

  constructor :streaminator
  
  
  def find_file_in_collection(file_name, file_list, complain, extra_message="")
    file_to_find = nil
    
    file_list.each do |item|
      base_file = File.basename(item)

      # case insensitive comparison
      if (base_file.casecmp(file_name) == 0)
        # case sensitive check
        if (base_file == file_name)
          file_to_find = item
          break
        else
          blow_up(file_name, "However, a filename having different capitalization was found: '#{item}'.")
        end
      end
      
    end
    
    case (complain)
      when :error then blow_up(file_name, extra_message) if (file_to_find.nil?)
      when :warn  then gripe(file_name, extra_message)   if (file_to_find.nil?)
      #when :ignore then      
    end
    
    return file_to_find
  end

  private
  
  def blow_up(file_name, extra_message="")
    error = "ERROR: Found no file '#{file_name}' in search paths."
    error += ' ' if (extra_message.length > 0)
    @streaminator.stderr_puts(error + extra_message, Verbosity::ERRORS)
    raise
  end
  
  def gripe(file_name, extra_message="")
    warning = "WARNING: Found no file '#{file_name}' in search paths."
    warning += ' ' if (extra_message.length > 0)
    @streaminator.stderr_puts(warning + extra_message, Verbosity::COMPLAIN)
  end

end


Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
ceedling-0.13.0 lib/file_finder_helper.rb
ceedling-0.13.0.rc1 lib/file_finder_helper.rb
ceedling-0.12.2 new_project_template/vendor/ceedling/lib/file_finder_helper.rb
ceedling-0.12.1 new_project_template/vendor/ceedling/lib/file_finder_helper.rb
ceedling-0.12.0 new_project_template/vendor/ceedling/lib/file_finder_helper.rb
ceedling-0.11.2 new_project_template/vendor/ceedling/lib/file_finder_helper.rb
ceedling-0.11.1 new_project_template/vendor/ceedling/lib/file_finder_helper.rb
ceedling-0.11.0 new_project_template/vendor/ceedling/lib/file_finder_helper.rb
ceedling-0.10.0 new_project_template/vendor/ceedling/lib/file_finder_helper.rb
ceedling-0.9.4 new_project_template/vendor/ceedling/lib/file_finder_helper.rb
ceedling-0.9.2 new_project_template/vendor/ceedling/lib/file_finder_helper.rb
ceedling-0.9.0 new_project_template/vendor/ceedling/lib/file_finder_helper.rb
ceedling-0.0.18 new_project_template/vendor/ceedling/lib/file_finder_helper.rb
ceedling-0.0.17 new_project_template/vendor/ceedling/lib/file_finder_helper.rb
ceedling-0.0.16 new_project_template/vendor/ceedling/lib/file_finder_helper.rb
ceedling-0.0.15 new_project_template/vendor/ceedling/lib/file_finder_helper.rb
ceedling-0.0.14 new_project_template/vendor/ceedling/lib/file_finder_helper.rb
ceedling-0.0.13 new_project_template/vendor/ceedling/lib/file_finder_helper.rb
ceedling-0.0.12 new_project_template/vendor/ceedling/lib/file_finder_helper.rb
ceedling-0.0.8 new_project_template/vendor/ceedling/lib/file_finder_helper.rb