comparison +mpm/MatlabPathManager.m @ 28:0842a1b2ac7e

Factor out function for checking if a subpath is active
author Jonatan Werpers <jonatan@werpers.com>
date Tue, 18 Sep 2018 13:18:02 +0200
parents 05a8b30ee4a7
children 91724783a931
comparison
equal deleted inserted replaced
27:05a8b30ee4a7 28:0842a1b2ac7e
96 function b = verify(obj, projectFolder) 96 function b = verify(obj, projectFolder)
97 mpath = obj.matlabPath(); 97 mpath = obj.matlabPath();
98 sp = obj.projectSubpaths(projectFolder); 98 sp = obj.projectSubpaths(projectFolder);
99 99
100 for i = 1:length(sp) 100 for i = 1:length(sp)
101 if ~isAtTop(sp{i}, fullfile(projectFolder, sp{i}), mpath) 101 if ~subpathIsActive(fullfile(projectFolder,sp{i}), mpath)
102 b = false; 102 b = false;
103 return; 103 return;
104 end 104 end
105 end 105 end
106 b = true; 106 b = true;
107
108 function b = isAtTop(subpath, fullsubpath, paths)
109 for i = 1:length(paths)
110 if ~endsWith(paths{i}, subpath)
111 continue
112 end
113
114 b = strcmp(fullsubpath, paths{i});
115 return
116 end
117
118 b = false;
119 end
120
121 % TODO: Refactor this into several methods?
122 end 107 end
123 108
124 % Unload all loaded subpaths. The matlab path should be returned to it's original state 109 % Unload all loaded subpaths. The matlab path should be returned to it's original state
125 function clear(obj) 110 function clear(obj)
126 sp = obj.loadedSubpaths(); 111 sp = obj.loadedSubpaths();
130 end 115 end
131 end 116 end
132 end 117 end
133 end 118 end
134 119
120 % Test if the path p is active among folders in path with the same final foldername
121 function b = subpathIsActive(p, paths)
122 pathparts = split(p, filesep);
123 foldername = pathparts{end};
124
125 for i = 1:length(paths)
126 if ~endsWith(paths{i}, foldername)
127 % Ignore files with different end foldername
128 continue
129 end
130
131 b = strcmp(p, paths{i});
132 return
133 end
134
135 b = false;
136 end
137
135 % TODO: Organize order of methods 138 % TODO: Organize order of methods
136 % TODO: Add flag for being persistent or not? (savepath or not) 139 % TODO: Add flag for being persistent or not? (savepath or not)
137 % TODO: Make is at top a method?