Module: DatabaseTransform::SchemaTableRecordMapping

Defined in:
lib/database_transform/schema_table_record_mapping.rb

Instance Method Summary collapse

Instance Method Details

#memoize_transform(old_primary_key, result) ⇒ Object



27
28
29
30
# File 'lib/database_transform/schema_table_record_mapping.rb', line 27

def memoize_transform(old_primary_key, result)
  @transformed ||= {}
  @transformed[old_primary_key] = result
end

#transform(old_primary_key) ⇒ Object

Obtains the result of transforming the record with the given primary key.

Parameters:

  • old_primary_key

    The primary key of the record to obtain the result for.

Returns:

  • The new record after transformation.

Raises:

  • (ActiveRecord::RecordNotFound)

    When the primary has not been transformed, or the primary key does not exist.



7
8
9
10
11
12
13
14
# File 'lib/database_transform/schema_table_record_mapping.rb', line 7

def transform(old_primary_key)
  @transformed ||= {}
  unless @transformed.has_key?(old_primary_key)
    raise ActiveRecord::RecordNotFound.new("Key #{old_primary_key} in #{table_name}")
  end

  @transformed[old_primary_key]
end

#transformed?(old_primary_key) ⇒ Boolean

Checks if the given primary key has been transformed.

Parameters:

  • old_primary_key

    The primary key of the record to obtain the result for.

Returns:

  • (Boolean)

    True if the record has been transformed.



20
21
22
23
# File 'lib/database_transform/schema_table_record_mapping.rb', line 20

def transformed?(old_primary_key)
  @transformed ||= {}
  @transformed.has_key?(old_primary_key)
end