Data Building with Symbiont

In the previous post in data setting, I talked about the start of a data builder pattern. Sometimes it’s nice to have your automation use descriptive phrases that stand in for specific bits of data. So here I’ll describe how Symbiont allows this by adhering to a data builder pattern.

As with the last post, here I’ll be using the warp factor calculator area of the Dialogic site. You might want to follow the directions in the last post regarding having a local copy available.

The data builder module builds off of the data setter concept. To see how this works, start with the following script and page definition:

Notice in particular the line that includes the DataBuilder. I’ll come back to that. With that in place, put in the following script logic:

Here notice that the using action (from data setter) is being used but is also referring to another action, data_about. What this is doing is telling Symbiont that you want to use a specific set of data that is given by a name (in this case, “alpha centauri”). Note that to be able to call data_about directly as is done here, you must have the include line that brings in the DataBuilder module.

But where is this data coming from? Symbiont has a convention built in that if you don’t tell it a specific data file to use, it will assume a file called default.yml that is stored in a data directory. To see this work, create a directory called data and put the following in a file called default.yml:

So here the “data_about” action will now find the identifier called “alpha centauri”. That file contains names that match element definitions on the page definition. For each element, there is a data value specified.

You are able to specify specific data, just as you could with the data setter. So, for example, the above action could be this:

Here the data set for ‘alpha centauri’ will be used but the value of distance in that file (4.3) will be replaced by the specified new value for distance (12).

What if you want to use a data file that is not called default.yml? What if, for example, I have my ‘alpha centauri’ data set in a file called ‘warp_factor.yml’. If that file is in your data directory, you could simply do this:

That still assumes the warp_factor file is in the data directory. What if you want to have data files in a different directory? You can specify a directory that the DataBuilder module should use. Let’s say my warp_factor.yml is stored in a common/data directory. You could add a command like this to your script:

Then the same line as before

will now look for a warp_factor.yml file in the common/data directory.

Finally, you can load up a specific data file if you want by doing this:

That allows you to get access to the data and perhaps sent it into a further data building mechanism that you include as part of your library.

At this point, I’m not sure how much further I’m going to evolve the data builder pattern in Symbiont. The goal was to provide a base upon which you can build your own data mechanisms that are specific to your needs. I’m trying not to clutter the Symbiont code base with too many of my own assumptions on what people will need. So right now I’ve put in a base that allows you to use concise and expressive statements to work with data.

Share

About Jeff Nyman

Anything I put here is an approximation of the truth. You're getting a particular view of myself ... and it's the view I'm choosing to present to you. If you've never met me before in person, please realize I'm not the same in person as I am in writing. That's because I can only put part of myself down into words. If you have met me before in person then I'd ask you to consider that the view you've formed that way and the view you come to by reading what I say here may, in fact, both be true. I'd advise that you not automatically discard either viewpoint when they conflict or accept either as truth when they agree.
This entry was posted in Automation, Symbiont. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *