Class: Bake::Root
- Inherits:
-
Object
- Object
- Bake::Root
- Defined in:
- lib/common/root.rb
Instance Attribute Summary collapse
-
#depth ⇒ Object
Returns the value of attribute depth.
-
#dir ⇒ Object
Returns the value of attribute dir.
Class Method Summary collapse
- .calc_def_roots(dir) ⇒ Object
- .calc_roots_bake(dir) ⇒ Object
- .equal(rootArrayA, rootArrayB) ⇒ Object
- .extract_depth(str) ⇒ Object
- .search_to_depth(root, baseName, depth) ⇒ Object
- .searchRootsFile(dir) ⇒ Object
- .uniq(array) ⇒ Object
Instance Method Summary collapse
-
#initialize(directory, search_depth) ⇒ Root
constructor
A new instance of Root.
Constructor Details
#initialize(directory, search_depth) ⇒ Root
Returns a new instance of Root.
7 8 9 10 |
# File 'lib/common/root.rb', line 7 def initialize(directory,search_depth) @dir = directory @depth = search_depth end |
Instance Attribute Details
#depth ⇒ Object
Returns the value of attribute depth.
5 6 7 |
# File 'lib/common/root.rb', line 5 def depth @depth end |
#dir ⇒ Object
Returns the value of attribute dir.
4 5 6 |
# File 'lib/common/root.rb', line 4 def dir @dir end |
Class Method Details
.calc_def_roots(dir) ⇒ Object
78 79 80 |
# File 'lib/common/root.rb', line 78 def self.calc_def_roots(dir) return [Root.new(File.dirname(dir), nil)] end |
.calc_roots_bake(dir) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/common/root.rb', line 59 def self.calc_roots_bake(dir) def_roots = [] rootsFile = (File.file?(dir) ? dir : searchRootsFile(dir)) if (rootsFile) File.open(rootsFile).each do |line| line = line.split("#")[0].strip.gsub(/[\\]/,'/') if line != "" root = Root.extract_depth(line) root.dir = root.dir[0..-2] if root.dir.end_with?("/") if !File.is_absolute?(root.dir) root.dir = File.(File.dirname(rootsFile) + "/" + root.dir) end def_roots << root end end end return def_roots end |
.equal(rootArrayA, rootArrayB) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/common/root.rb', line 40 def self.equal(rootArrayA, rootArrayB) return false if rootArrayA.length != rootArrayB.length rootArrayA.each_with_index do |a, i| b = rootArrayB[i] return false if (a.dir != b.dir) || (a.depth != b.depth) end return true end |
.extract_depth(str) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/common/root.rb', line 30 def self.extract_depth(str) regex = /\s*(\S*)\s*,\s*(\d+)\s*\z/ scan_res = str.scan(regex) if scan_res.length > 0 return Root.new(scan_res[0][0],scan_res[0][1].to_i) else return Root.new(str, nil) end end |
.search_to_depth(root, baseName, depth) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/common/root.rb', line 82 def self.search_to_depth(root, baseName, depth) return Dir.glob(baseName) if File.is_absolute?(baseName) if not File.exist?(root) Bake.formatter.printError("Root #{root} does not exist.") ExitHelper.exit(1) end if depth != nil array = Array.new(depth+1) {|i| root + '/*'*i + '/' + baseName} return Dir.glob(array).sort else # when using junctions, /**/ does not work, so the glob is splitted into two globs to find at least first level projects str1 = "#{root}/#{baseName}" str2 = "#{root}/*/**/#{baseName}" return (Dir.glob(str1) + Dir.glob(str2)).sort end end |
.searchRootsFile(dir) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/common/root.rb', line 49 def self.searchRootsFile(dir) rootsFile = dir+"/roots.bake" return rootsFile if File.exist?(rootsFile) parent = File.dirname(dir) return searchRootsFile(parent) if parent != dir return nil end |
.uniq(array) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/common/root.rb', line 12 def self.uniq(array) maxDepth = {} newArray = [] array.each do |r| if maxDepth.has_key?r.dir d = maxDepth[r.dir] if !d.nil? && (r.depth.nil? || d < r.depth) # not covered yet newArray << r maxDepth[r.dir] = r.depth end else newArray << r maxDepth[r.dir] = r.depth end end return newArray end |