lib/config_scripts/seeds/seed_set.rb
# This method finds a record based on a unique identifier in the seed
# data.
#
# This will look for a seed type for the class, and use its
# {#record_for_seed_identifier} method to get the record.
#
# The result of this will be memoized so that we do not have to keep
# looking up the records.
#
# @param [Class] klass
#   The model class for the record we are finding.
#
# @param [Array<String>] identifier
#   The identifier components from the seed data.
#
# @return [ActiveRecord::Base]
#   The model record.
This method finds a record based on a unique identifier in the seed
data.

This will look for a seed type for the class, and use its
{#record_for_seed_identifier} method to get the record.

The result of this will be memoized so that we do not have to keep
looking up the records.
This method finds a record based on a unique identifier in the seed data . This will look for a seed type for the class and use its { #record_for_seed_identifier } method to get the record . The result of this will be memoized so that we do not have to keep looking up the records .
def record_for_seed_identifier(klass, identifier)
        seed_type = self.seed_type_for_class(klass)
        return nil unless seed_type
        @record_cache ||= {}
        @record_cache[klass] ||= {}
        cache_identifier = identifier.dup
        while cache_identifier.any?
          record = @record_cache[klass][cache_identifier]
          if record
            cache_identifier.count.times { identifier.shift }
            return record
          end
          cache_identifier.pop
        end
        if seed_type
          cache_identifier = identifier.dup
          record = seed_type.record_for_seed_identifier(identifier)
          if identifier.any?
            cache_identifier = cache_identifier[0...-1*identifier.count]
          end
          @record_cache[klass][cache_identifier] = record
        end
        record
      end
def record_for_seed_identifier ( klass , identifier ) seed_type = self . seed_type_for_class ( klass ) return nil unless seed_type @record_cache ||= { } @record_cache [ klass ] ||= { } cache_identifier = identifier . dup while cache_identifier . any? record = @record_cache [ klass ] [ cache_identifier ] if record cache_identifier . count . times { identifier . shift } return record end cache_identifier . pop end if seed_type cache_identifier = identifier . dup record = seed_type . record_for_seed_identifier ( identifier ) if identifier . any? cache_identifier = cache_identifier [ 0 ... - 1 * identifier . count ] end @record_cache [ klass ] [ cache_identifier ] = record end record end
This method finds a record based on a unique identifier in the seed
data.
This method finds a record based on a unique identifier in the seed data .
The model record.
The model record .
ActiveRecord::Base
klass
<not_specific>
identifier
<not_specific>
<not_specific>
identifier The identifier components from the seed data.
identifier The identifier components from the seed data .