The TerraPop Metadata tracks and documents the full process of preparing the data that will be fed into the TerraPop application. part of this process involveds manipulating geographic data, namely maps. These maps may come from a variety of sources, then depending on the final map needed to match a set of variables, these maps are run through a series of processing steps. There are 10 different processing steps to be exact and no single complete process will look the same.
My task at hand was to construct a streamlined UI that would allow users to craft a full map process with any combination of map steps. The main models involved in this process look a bit like this (code samples were simplified for demonstration purposes):
And all of the process steps, 10 in total, were structured like this: /app/models/process_steps
The first tricky issue I'd like to tackle is to discuss how I created the methods in the ProcessStepsController to handle a process_step with an association to to 1 of potentially 10 different step types.
To faciliate this connection, I created a field in the step_type_id field in the ProcessStep model forming a has_one/belongs_to relationship with a domain model consisting of the 10 different steps. Here is how this domain model was seeded: /db/seeds.rb
To make it possible to write simple crud methods in the ProcessStepsController required heavy use of meta programming, including the send(), instance_variable_set(), and instance_variable_get() methods. For example, to set instance variables for the set
step_type = StepType.find(@process_step.step_type_id).name.downcase + "_step"
instance_variable_set('@'+ step_type, @process_step.send(step_type))
Put it all together, and the create method looks like this: /app/controllers/process_steps_controller.rb
(See bottom of post for full ProcessStepsController code.)