module Builddir
Constants
- NAME
- VERSION
Public Class Methods
Searches through the mapping for a direct path match
@param mapping [Array<Array(String, String)>] the mapping which should checked @param path [String] path of the searched directory @return [nil, { Symbol => String,Symbol}] the found mapping. nil on error
# File lib/builddir.rb, line 45 def Builddir.findExactMapping(mapping,path) mapping.each_with_index do |entry,index| if entry[0] == path return { :srcDir => entry[0], :buildDir => entry[1], :index => index, :type => :SRC_DIR } elsif entry[1] == path return { :srcDir => entry[0], :buildDir => entry[1], :index => index, :type => :BUILD_DIR } end end return nil end
Searches through the mapping for a path match. Parent directories are considered for the matching as well.
@param mapping [Array<Array(String, String)>] the mapping which should checked @param path [String] path of the searched directory @return [nil, { Symbol => String,Symbol}] the found mapping. nil on error
# File lib/builddir.rb, line 62 def Builddir.findMapping(mapping,path) lastpn = nil pn = Pathname.new(path) while pn != lastpn do entry = findExactMapping(mapping,pn.to_s) return entry if entry lastpn = pn pn = pn.parent() end return nil end
Determine the build directory base path @return [String] the base path for the build directories
# File lib/builddir.rb, line 76 def Builddir.getBuildBasePath() return ENV['DEFAULT_BUILDDIR'] || "/tmp/builddir" end
Return the directory with the project libraries stackoverflow.com/a/5805783
@return [String] path to the library directory
# File lib/builddir/utils.rb, line 9 def Builddir.getGemLibdir t = ["#{File.dirname(File.expand_path($0))}/../lib/#{NAME}", "#{Gem.dir}/gems/#{NAME}-#{VERSION}/lib/#{NAME}"] t.each {|i| return i if File.readable?(i) } raise "both paths are invalid: #{t}" end
Determine path to the mapping file @return [String] the path to the mapping file
# File lib/builddir.rb, line 82 def Builddir.getMappingsFilePath() return File.join(getBuildBasePath(),"builddir_mapping.yml") end
Loads the BuildDir <-> SourceDir mapping from the file
@param file [String] path of the mapping file @return [nil, Array<Array(String, String)>] The loaded mapping. nil on error
# File lib/builddir.rb, line 14 def Builddir.loadMapping(file = nil) file = getMappingsFilePath() if file.nil? begin mapping = YAML::load_file(file) rescue mapping = nil end return mapping end
Saves the BuildDir <-> SourceDir mapping to a file
@param mapping [Array<Array(String, String)>] the mapping which should be saved @param file [String] path of the mapping file
# File lib/builddir.rb, line 28 def Builddir.saveMapping(mapping, file = nil) file = getMappingsFilePath() if file.nil? # create the directory when needed dirname = File.dirname(file) FileUtils.mkdir_p(dirname) unless File.exists?(dirname) File.open(file, 'w') do |f| f.write mapping.to_yaml end end