Class: NcsNavigator::Warehouse::Filters::AddIdPrefixFilter

Inherits:
Object
  • Object
show all
Includes:
RecordIdChangingFilterSupport
Defined in:
lib/ncs_navigator/warehouse/filters/add_id_prefix_filter.rb

Overview

A filter which adds a prefix to the ID for every record of a given type. This filter is stateful and so must be instantiated.

Instance Attribute Summary

Attributes included from RecordIdChangingFilterSupport

#model

Instance Method Summary collapse

Methods included from RecordIdChangingFilterSupport

#call

Constructor Details

#initialize(configuration, options = {}) ⇒ AddIdPrefixFilter

Creates the filter.

In addition to the options specified here, this constructor accepts the options defined on RecordIdChangingFilterSupport#initialize.

Parameters:

  • configuration (Configuration)

    the warehouse configuration.

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :prefix (String)

    the prefix to apply.



20
21
22
23
# File 'lib/ncs_navigator/warehouse/filters/add_id_prefix_filter.rb', line 20

def initialize(configuration, options={})
  super
  @prefix = options[:prefix] or fail 'Please specify a :prefix.'
end

Instance Method Details

#changed_id(original_id) ⇒ String

Returns the ID with the prefix applied.

Parameters:

  • original_id (String)

    the incoming ID.

Returns:

  • (String)

    the ID with the prefix applied.



28
29
30
# File 'lib/ncs_navigator/warehouse/filters/add_id_prefix_filter.rb', line 28

def changed_id(original_id)
  "#{@prefix}#{original_id}" if original_id
end