Module: Build::URI::Base

Included in:
Absolute, Relative, Triplet
Defined in:
lib/build/uri/base.rb

Instance Method Summary collapse

Instance Method Details

#+(other) ⇒ Object



53
54
55
# File 'lib/build/uri/base.rb', line 53

def + other
	merge(URI[other])
end

#basenameObject



65
66
67
# File 'lib/build/uri/base.rb', line 65

def basename
	clone.path = self.path.rpartition(SEPARATOR).last
end

#dirnameObject



57
58
59
60
61
62
63
# File 'lib/build/uri/base.rb', line 57

def dirname
	clone = self.dup
	
	clone.path = self.path.rpartition(SEPARATOR).first
	
	return clone
end

#merge(other, directory: true) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/build/uri/base.rb', line 27

def merge(other, directory: true)
	if self.path.nil? || other.absolute?
		return other
	else
		clone = self.dup
		
		if other.path.start_with?(SEPARATOR)
			clone.path = other.path
		elsif directory
			# We try to avoid ending up with more than one slash:
			if self.path.end_with?(SEPARATOR)
				clone.path = [self.path, other.path].join
			else
				clone.path = [self.path, other.path].join(SEPARATOR)
			end
		else
			# The basename of a non-directory path is ignored when merged.
			dirname, _, basename = self.path.rpartition(SEPARATOR)
			
			clone.path = [dirname, other.path].join(SEPARATOR)
		end
		
		return clone.freeze
	end
end