Class: ActiveRecord::FixtureSet::ClassCache

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

Instance Method Summary collapse

Constructor Details

#initialize(class_names, config) ⇒ ClassCache

Returns a new instance of ClassCache.


465
466
467
468
469
470
471
# File 'activerecord/lib/active_record/fixtures.rb', line 465

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 { |klass_name, klass| !insert_class(@class_names, klass_name, klass) }
end

Instance Method Details

#[](fs_name) ⇒ Object


473
474
475
476
477
478
# File 'activerecord/lib/active_record/fixtures.rb', line 473

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