Make a Custom File Reader

This is good example of how we can usePrefix Namespaces for Separating Concerns by building a custom file reader component which has a simple interface for a unique purpose rather than using a general purpose no code solution - see The problem with no-code solutions.

Here’s a scenario:

A large lab needs to have a file reading component which can feed files from different customers based on the prefix of the file, i.e. some files start with JJ99, others XYZ etc. depending on the source.

Let’s do it!

This component generates some test files to make it easier to learn how to make a custom file reader.

You can useFrom URL to import the component.

Copy paste the URL from here:

git@bitbucket.org:interfaceware/file_tutorial.git

Refer to Edit a Component to see how it's done if you have not done this before.

To simplify the tutorial we have set these up a ClientList with the filename prefix Ids. Click on the config.json and you should see:

See Custom Fields to understand how this was created.

Navigate to MatchRules.lua in the Project Tree. This is the function we need to alter:

function MatchFile(FileName) return true end

The file reader component is deliberately simple and uses separation of concerns to make it more obvious how to modify the code to meet new needs. We need this function to return true when the matching criteria are met.

Change the matching to add in two lines so we can see the filenames we need to filter on.

function MatchFile(FileName) local JustFileName = FILfilename(FileName) trace(JustFileName) return true end

These are the concepts we have used:

You’re done! The next steps are how you could further refine the code

There is no limit to how you can streamline the usage of a custom component - if that helps address a bottleneck, then it is well worth it.  

Â