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.



559
560
561
# File 'activesupport/lib/active_support/dependencies.rb', line 559

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

Instance Method Details

#clear!Object



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

def clear!
  @store.clear
end

#empty?Boolean

Returns:

  • (Boolean)


563
564
565
# File 'activesupport/lib/active_support/dependencies.rb', line 563

def empty?
  @store.empty?
end

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



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

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

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


567
568
569
# File 'activesupport/lib/active_support/dependencies.rb', line 567

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

#safe_get(key) ⇒ Object



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

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

#store(klass) ⇒ Object

Raises:

  • (ArgumentError)


582
583
584
585
586
587
# File 'activesupport/lib/active_support/dependencies.rb', line 582

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