Class: Renalware::UKRDC::TreatmentTimeline::RemapModelTableNamesToTheirPreparedEquivalents
- Inherits:
-
Object
- Object
- Renalware::UKRDC::TreatmentTimeline::RemapModelTableNamesToTheirPreparedEquivalents
- Defined in:
- app/models/renalware/ukrdc/treatment_timeline/remap_model_table_names_to_their_prepared_equivalents.rb
Overview
When generating the treatment timeline, sites may want to pre-prepare a massaged version of say hd_profiles, in order to correct any anomalies. This service object will remap the table_name of the supplied (or default models) to the ‘ukrdc_prepared_*’ version if it exists. Otrherwise it will not change the table name. Note that this can only be done when executing as a rake task (which has its own process) as I beleive changing the table_name will affect all threads in the same process - so doing this in a puma process would mean users start to see only the contents of the ukrdc_prepared_tables. Not good :0.
Defined Under Namespace
Classes: ExecutionNotAllowedError
Constant Summary collapse
Instance Method Summary collapse
-
#call(models = MODELS) ⇒ Object
Saves the original table names for the array of models classes remaps to its ukrdc_prepared_* varaient if it exists, yields to allow the claling process to do its thing, then importantly winds back to the original table names.
Instance Method Details
#call(models = MODELS) ⇒ Object
Saves the original table names for the array of models classes remaps to its ukrdc_prepared_* varaient if it exists, yields to allow the claling process to do its thing, then importantly winds back to the original table names.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/models/renalware/ukrdc/treatment_timeline/remap_model_table_names_to_their_prepared_equivalents.rb', line 26 def call(models = MODELS) fail_unless_running_in_rake_or_rspec models = Array(models) original_table_names = models.map(&:table_name) models.each do |model_class| prepared_table_name = prepared_table_name_for(model_class.table_name) model_class.table_name = prepared_table_name if table_exists?(prepared_table_name) end yield if block_given? models.each_with_index do |model_class, index| model_class.table_name = original_table_names[index] end end |