Class: ActiveSupport::Dependencies::ClassCache

Inherits:
Object
  • Object
show all
Defined in:
activesupport/lib/active_support/dependencies.rb

Instance Method Summary collapse

Constructor Details

#initializeClassCache

Returns a new instance of ClassCache.


569
570
571
# File 'activesupport/lib/active_support/dependencies.rb', line 569

def initialize
  @store = Concurrent::Map.new
end

Instance Method Details

#clear!Object


599
600
601
# File 'activesupport/lib/active_support/dependencies.rb', line 599

def clear!
  @store.clear
end

#empty?Boolean

Returns:

  • (Boolean)

573
574
575
# File 'activesupport/lib/active_support/dependencies.rb', line 573

def empty?
  @store.empty?
end

#get(key) ⇒ Object Also known as: []


581
582
583
584
# File 'activesupport/lib/active_support/dependencies.rb', line 581

def get(key)
  key = key.name if key.respond_to?(:name)
  @store[key] ||= Inflector.constantize(key)
end

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)

577
578
579
# File 'activesupport/lib/active_support/dependencies.rb', line 577

def key?(key)
  @store.key?(key)
end

#safe_get(key) ⇒ Object


587
588
589
590
# File 'activesupport/lib/active_support/dependencies.rb', line 587

def safe_get(key)
  key = key.name if key.respond_to?(:name)
  @store[key] ||= Inflector.safe_constantize(key)
end

#store(klass) ⇒ Object

Raises:

  • (ArgumentError)

592
593
594
595
596
597
# File 'activesupport/lib/active_support/dependencies.rb', line 592

def store(klass)
  return self unless klass.respond_to?(:name)
  raise(ArgumentError, 'anonymous classes cannot be cached') if klass.name.empty?
  @store[klass.name] = klass
  self
end