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.



520
521
522
# File 'activesupport/lib/active_support/dependencies.rb', line 520

def initialize
  @store = ThreadSafe::Cache.new
end

Instance Method Details

#clear!Object



550
551
552
# File 'activesupport/lib/active_support/dependencies.rb', line 550

def clear!
  @store.clear
end

#empty?Boolean

Returns:

  • (Boolean)


524
525
526
# File 'activesupport/lib/active_support/dependencies.rb', line 524

def empty?
  @store.empty?
end

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



532
533
534
535
# File 'activesupport/lib/active_support/dependencies.rb', line 532

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

#key?(key) ⇒ Boolean

Returns:

  • (Boolean)


528
529
530
# File 'activesupport/lib/active_support/dependencies.rb', line 528

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

#safe_get(key) ⇒ Object



538
539
540
541
# File 'activesupport/lib/active_support/dependencies.rb', line 538

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

#store(klass) ⇒ Object

Raises:

  • (ArgumentError)


543
544
545
546
547
548
# File 'activesupport/lib/active_support/dependencies.rb', line 543

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