Module: DataStructureBuilder
- Extended by:
- ActiveSupport::Concern
- Includes:
- ActiveModel::Model
- Included in:
- Message::Message, RunCsv::OntSampleSheet, RunCsv::PacbioSampleSheet, RunCsv::PacbioSampleSheetLegacy
- Defined in:
- app/exchanges/data_structure_builder.rb
Overview
Creates a message in the correct structure for the warehouse
Instance Method Summary collapse
- #data_structure ⇒ Object
-
#instance_value(object, field, parent = nil) ⇒ Object
Find the instance value for each field If the field is a: * [string] - return the value * [model] - take the value split it by the full stop and recursively send the method to the object e.g.
Instance Method Details
#data_structure ⇒ Object
14 15 16 17 18 |
# File 'app/exchanges/data_structure_builder.rb', line 14 def data_structure configuration.fields.each_with_object({}) do |(k, v), r| r[k] = instance_value(object, v, :root) end end |
#instance_value(object, field, parent = nil) ⇒ Object
Find the instance value for each field If the field is a: * [string] - return the value * [model] - take the value split it by the full stop and recursively send the method to the object e.g. it is object.foo.bar will first evaluate foo and then apply bar * [parent_model] - as above, but applied to the parent object * [constant] - Takes the constant and applies the method chain to it e.g DateTime.now * [array] - usually an array of fields * [self] - applies to the method to the current (builder) object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/exchanges/data_structure_builder.rb', line 32 def instance_value(object, field, parent = nil) # # rubocop:disable Metrics/MethodLength case field[:type] when :string field[:value] when :model evaluate_field(object, field[:value]) when :parent_model evaluate_field(parent, field[:value]) when :constant const_obj, *methods = field[:value].split('.') evaluate_method_chain(const_obj.constantize, methods) when :array build_children(object, field) when :self evaluate_field(self, field[:value]) end end |