Module: NcsNavigator::Warehouse::Filters::RecordIdChangingFilterSupport
- Included in:
- AddIdPrefixFilter, RemoveIdPrefixFilter
- Defined in:
- lib/ncs_navigator/warehouse/filters/record_id_changing_filter_support.rb
Overview
A framework for a filter which modifies all ID values for a particular
record type. The class into which it is mixed must implement changed_id
,
a method which takes an incoming ID value and provides the replacement
value.
Instance Attribute Summary collapse
-
#model ⇒ Class
readonly
The warehouse model for which the ID will be prefixed.
Instance Method Summary collapse
-
#call(records) ⇒ Array<MdesModel>
Modifies all IDs for the target record type according to the consumer-defined
changed_id
method. -
#initialize(configuration, options = {}) ⇒ Object
An inheritable constructor for filters which mix in this module.
Instance Attribute Details
#model ⇒ Class (readonly)
Returns the warehouse model for which the ID will be prefixed.
12 13 14 |
# File 'lib/ncs_navigator/warehouse/filters/record_id_changing_filter_support.rb', line 12 def model @model end |
Instance Method Details
#call(records) ⇒ Array<MdesModel>
Modifies all IDs for the target record type according to the
consumer-defined changed_id
method.
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ncs_navigator/warehouse/filters/record_id_changing_filter_support.rb', line 45 def call(records) records.each do |rec| if rec.is_a?(model) change_primary_key(rec) # see the class comment on {CompositeFilter} rec.instance_eval { remove_instance_variable(:@_key) if defined?(@_key) } end change_foreign_keys_if_any(rec) end end |
#initialize(configuration, options = {}) ⇒ Object
An inheritable constructor for filters which mix in this module.
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ncs_navigator/warehouse/filters/record_id_changing_filter_support.rb', line 24 def initialize(configuration, ={}) @model = if [:table] configuration.model([:table]) elsif [:model] configuration.model([:model]) else fail 'Please specify either :table or :model.' end unless self.respond_to?(:changed_id) fail "#{self.class} does not implement changed_id" end end |