Module: Builddir
- Defined in:
- lib/builddir.rb,
lib/builddir/utils.rb,
lib/builddir/version.rb
Constant Summary collapse
- NAME =
'builddir'
- VERSION =
'0.1.4'
Class Method Summary collapse
-
.findExactMapping(mapping, path) ⇒ nil, { Symbol => String,Symbol}
Searches through the mapping for a direct path match.
-
.findMapping(mapping, path) ⇒ nil, { Symbol => String,Symbol}
Searches through the mapping for a path match.
-
.getBuildBasePath ⇒ String
Determine the build directory base path.
-
.getGemLibdir ⇒ String
Return the directory with the project libraries stackoverflow.com/a/5805783.
-
.getMappingsFilePath ⇒ String
Determine path to the mapping file.
-
.loadMapping(file = nil) ⇒ nil, Array<Array(String, String)>
Loads the BuildDir <-> SourceDir mapping from the file.
-
.saveMapping(mapping, file = nil) ⇒ Object
Saves the BuildDir <-> SourceDir mapping to a file.
Class Method Details
.findExactMapping(mapping, path) ⇒ nil, { Symbol => String,Symbol}
Searches through the mapping for a direct path match
45 46 47 48 49 50 51 52 53 54 |
# 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 |
.findMapping(mapping, path) ⇒ nil, { Symbol => String,Symbol}
Searches through the mapping for a path match. Parent directories are considered for the matching as well.
62 63 64 65 66 67 68 69 70 71 72 |
# 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 |
.getBuildBasePath ⇒ String
Determine the build directory base path
76 77 78 |
# File 'lib/builddir.rb', line 76 def Builddir.getBuildBasePath() return ENV['DEFAULT_BUILDDIR'] || "/tmp/builddir" end |
.getGemLibdir ⇒ String
Return the directory with the project libraries stackoverflow.com/a/5805783
9 10 11 12 13 14 |
# 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 |
.getMappingsFilePath ⇒ String
Determine path to the mapping file
82 83 84 |
# File 'lib/builddir.rb', line 82 def Builddir.getMappingsFilePath() return File.join(getBuildBasePath(),"builddir_mapping.yml") end |
.loadMapping(file = nil) ⇒ nil, Array<Array(String, String)>
Loads the BuildDir <-> SourceDir mapping from the file
14 15 16 17 18 19 20 21 22 |
# 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 |
.saveMapping(mapping, file = nil) ⇒ Object
Saves the BuildDir <-> SourceDir mapping to a file
28 29 30 31 32 33 34 35 36 37 38 |
# 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 |