Class: ActiveSupport::Dependencies::ClassCache

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

Instance Method Summary collapse

Constructor Details

#initializeClassCache

Returns a new instance of ClassCache.



613
614
615
# File 'lib/active_support/dependencies.rb', line 613

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

Instance Method Details

#clear!Object



643
644
645
# File 'lib/active_support/dependencies.rb', line 643

def clear!
  @store.clear
end

#empty?Boolean

Returns:

  • (Boolean)


617
618
619
# File 'lib/active_support/dependencies.rb', line 617

def empty?
  @store.empty?
end

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



625
626
627
628
# File 'lib/active_support/dependencies.rb', line 625

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

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


621
622
623
# File 'lib/active_support/dependencies.rb', line 621

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

#safe_get(key) ⇒ Object



631
632
633
634
# File 'lib/active_support/dependencies.rb', line 631

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

#store(klass) ⇒ Object

Raises:

  • (ArgumentError)


636
637
638
639
640
641
# File 'lib/active_support/dependencies.rb', line 636

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