Module: NcsNavigator::Warehouse::Transformers::Database::DSL
- Defined in:
- lib/ncs_navigator/warehouse/transformers/database.rb
Overview
The DSL available when a class mixes in the Database module.
Instance Method Summary collapse
-
#bcdatabase(name_and_group = {})
Defines the bcdatabase specification to use when connecting to the database for this enumeration.
-
#ignored_columns(*columns) ⇒ Object
Indicates a set of columns which which should not be checked for used-ness by #model_row, even if the
:unused
option is set to:fail
. -
#on_unused_columns(setting = nil) ⇒ :ignore, :fail
What to do if are encountered by #model_row.
-
#produce_one_for_one(name, model_or_reference, options = {})
Define a translation from the results of a query into exactly one warehouse record per result row.
-
#produce_records(name, options = {}, &logic)
Define a translation from the results of a query into one or more warehouse records.
-
#record_producers ⇒ Array
The record producers defined by calls to #produce_records.
- #repository(repo_name)
-
#repository_name ⇒ Symbol
The name defined by a previous call to #repository, or the default.
Instance Method Details
#bcdatabase(name_and_group = {})
This method returns an undefined value.
Defines the bcdatabase specification to use when connecting to the database for this enumeration.
213 214 215 216 217 218 219 |
# File 'lib/ncs_navigator/warehouse/transformers/database.rb', line 213 def bcdatabase(name_and_group={}) if name_and_group.empty? @bcdatabase ||= { } else @bcdatabase = (self.bcdatabase || {}).merge(name_and_group) end end |
#ignored_columns(*columns) ⇒ Object
Indicates a set of columns which which should not be checked
for used-ness by #model_row, even if the :unused
option is
set to :fail
.
200 201 202 203 204 205 206 |
# File 'lib/ncs_navigator/warehouse/transformers/database.rb', line 200 def ignored_columns(*columns) if columns.empty? @ignored_columns ||= [] else @ignored_columns = columns.collect(&:to_s) end end |
#on_unused_columns(setting = nil) ⇒ :ignore, :fail
What to do if are encountered by #model_row. Default is
:ignore
but may be set to :fail
for all producers using
this method. The value set here may be overridden per
#model_row call.
188 189 190 191 192 193 194 |
# File 'lib/ncs_navigator/warehouse/transformers/database.rb', line 188 def on_unused_columns(setting=nil) if setting @on_unused_columns = setting else @on_unused_columns ||= :ignore end end |
#produce_one_for_one(name, model_or_reference, options = {})
This method returns an undefined value.
Define a translation from the results of a query into exactly one warehouse record per result row. This method, while more restrictive than #produce_records, allows for rapidly mapping data which is already a close match for MDES records.
The mapping uses a series of heuristics to map from the columns in each query result row to at most one MDES variable from the specified model.
- If the column appears as a key in the
:column_map
hash, use the associated value as the target variable name. - If there's a
:prefix
option, the column is named X, and there's a variable named prefixX, use that variable. - If the column is named X and there's a variable named X, use that variable.
- If the column is named X_code and there's a variable named X, use that variable.
- If the column is named X_code and there's a variable named X_id, use that variable.
- If the column is named X_other and there's a property named X_oth, use that variable.
304 305 306 307 308 309 310 311 |
# File 'lib/ncs_navigator/warehouse/transformers/database.rb', line 304 def produce_one_for_one(name, model_or_reference, ={}) [:column_map] = ([:column_map] || {}).inject({}) { |h, (k, v)| h[k.to_s] = v.to_s; h } [:ignored_columns] = ([:ignored_columns] || []).collect(&:to_s) record_producers << OneForOneProducer.new(name, .delete(:query), model_or_reference, self, ) end |
#produce_records(name, options = {}, &logic)
This method returns an undefined value.
Define a translation from the results of a query into one or more warehouse records.
The optional second parameter the logic
proc/block is a hash of
metadata. That metadata contains a single key:
- :configuration. Provides the Configuration in use by the warehouse that is executing this transformer. Among other things, this allows lookup of models Configuration#model based on the in-use MDES version.
253 254 255 |
# File 'lib/ncs_navigator/warehouse/transformers/database.rb', line 253 def produce_records(name, ={}, &logic) record_producers << RecordProducer.new(name, [:query], logic) end |
#record_producers ⇒ Array
The record producers defined by calls to #produce_records.
225 226 227 |
# File 'lib/ncs_navigator/warehouse/transformers/database.rb', line 225 def record_producers @record_producers ||= [] end |
#repository(repo_name)
This method returns an undefined value.
169 170 171 |
# File 'lib/ncs_navigator/warehouse/transformers/database.rb', line 169 def repository(repo_name) @repository_name = repo_name end |
#repository_name ⇒ Symbol
Returns The name defined by a previous call to #repository, or the default. The default is derived from the name of the class into which NcsNavigator::Warehouse::Transformers::Database is mixed.
177 178 179 |
# File 'lib/ncs_navigator/warehouse/transformers/database.rb', line 177 def repository_name @repository_name ||= name.demodulize.underscore.to_sym end |