Class: ActiveRecord::FixtureSet::ClassCache

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/fixtures.rb

Instance Method Summary collapse

Constructor Details

#initialize(class_names, config) ⇒ ClassCache

Returns a new instance of ClassCache.



457
458
459
460
461
462
463
464
465
466
467
468
469
# File 'lib/active_record/fixtures.rb', line 457

def initialize(class_names, config)
  @class_names = class_names.stringify_keys
  @config      = config

  # Remove string values that aren't constants or subclasses of AR
  @class_names.delete_if { |k,klass|
    unless klass.is_a? Class
      klass = klass.safe_constantize
      ActiveSupport::Deprecation.warn("The ability to pass in strings as a class name to `set_fixture_class` will be removed in Rails 4.2. Use the class itself instead.")
    end
    !insert_class(@class_names, k, klass)
  }
end

Instance Method Details

#[](fs_name) ⇒ Object



471
472
473
474
475
476
# File 'lib/active_record/fixtures.rb', line 471

def [](fs_name)
  @class_names.fetch(fs_name) {
    klass = default_fixture_model(fs_name, @config).safe_constantize
    insert_class(@class_names, fs_name, klass)
  }
end