Class: Disloku::Util::File

Inherits:
Object
  • Object
show all
Defined in:
lib/disloku/util/File.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filePath, basePath, target, change) ⇒ File

Returns a new instance of File.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/disloku/util/File.rb', line 18

def initialize(filePath, basePath, target, change)
	@srcPath = filePath
	@target = target
	@change = change

	fileSegments = File.getSegments(filePath)
	baseSegments = File.getSegments(basePath)
	index = 0
	while (fileSegments[index] == baseSegments[index])
		index += 1
	end

	@relativeSrcSegments = fileSegments[index..-1]
	@relativeDstSegments = target.mapPath(@relativeSrcSegments)
end

Instance Attribute Details

#changeObject

Returns the value of attribute change.



16
17
18
# File 'lib/disloku/util/File.rb', line 16

def change
  @change
end

#srcPathObject

Returns the value of attribute srcPath.



16
17
18
# File 'lib/disloku/util/File.rb', line 16

def srcPath
  @srcPath
end

Class Method Details

.getSegments(path) ⇒ Object



12
13
14
# File 'lib/disloku/util/File.rb', line 12

def self.getSegments(path)
	return path.split(/#{SPLIT_EXP}/)
end

Instance Method Details

#getAbsoluteDstPath(basePath = nil) ⇒ Object



46
47
48
49
# File 'lib/disloku/util/File.rb', line 46

def getAbsoluteDstPath(basePath = nil)
	basePath = basePath || @target.targetDir
	return ::File.join(basePath, *@relativeDstSegments)
end

#getRelativeDirSegmentsObject



38
39
40
# File 'lib/disloku/util/File.rb', line 38

def getRelativeDirSegments()
	return @segments[0..-2]
end

#getRelativeDstSegmentsObject



34
35
36
# File 'lib/disloku/util/File.rb', line 34

def getRelativeDstSegments()
	return @segments
end

#hasMapping?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/disloku/util/File.rb', line 42

def hasMapping?()
	return @relativeDstSegments != nil
end

#to_sObject



51
52
53
54
# File 'lib/disloku/util/File.rb', line 51

def to_s()
	operation = (@change.changeType == :deleted ? "x>" : "->")
	return "#{srcPath} #{operation} #{getAbsoluteDstPath()}"
end