Skip to content

Block_checkCompatibility

Max-Home-Tower edited this page Jul 1, 2020 · 1 revision

checkCompatibility

Method of nigeLab.Block. Returns an error if an element of the input cell array, requiredFields, is not present in the Fields property of the calling Block.

Usage

This method makes it much more convenient to debug something whenever a "hard-coded" Field is present in a method, and configuration is changed such that the required Field is no longer included in the initialized or linked data.

function isItCurly = myFun(blockObj,username)
% MYFUN  Ad hoc function that returns true if user hair is curly
%
%  blockObj = nigeLab.Block;
%  isItCurly = blockObj.myFun('FB'); % Evaluates to true

%% Put a check like this into your function, please
REQUIRED_FIELDS = {'User','HairType','HairLength'};
blockObj.checkCompatibility(REQUIRED_FIELDS);

%% Rest of function
switch blockObj.Meta.User % Here, **User** is "hard-coded" into the switch syntax
case 'FB'
   isItCurly = true;
case 'MM'
   if strcmpi(blockObj.Meta.HairLength,'long') % HairLength is "hard-coded"
      isItCurly = true;
   else
      isItCurly = false;
   end
case 'JB'
   isItCurly = false; 
otherwise
   isItCurly = strcmpi(blockObj.Meta.HairType,'curly'); % HairType is "hard-coded"
end

end

Clone this wiki locally