Class: ActiveSupport::Dependencies::ClassCache
Relationships & Source Files | |
Inherits: | Object |
Defined in: | activesupport/lib/active_support/dependencies.rb |
Class Method Summary
- .new ⇒ ClassCache constructor
Instance Attribute Summary
- #empty? ⇒ Boolean readonly
Instance Method Summary
-
#[](key)
Alias for #get.
- #clear!
- #get(key) (also: #[])
- #key?(key) ⇒ Boolean
- #safe_get(key)
- #store(klass)
Constructor Details
.new ⇒ ClassCache
# File 'activesupport/lib/active_support/dependencies.rb', line 552
def initialize @store = ThreadSafe::Cache.new end
Instance Attribute Details
#empty? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'activesupport/lib/active_support/dependencies.rb', line 556
def empty? @store.empty? end
Instance Method Details
#[](key)
Alias for #get.
# File 'activesupport/lib/active_support/dependencies.rb', line 568
alias :[] :get
#clear!
[ GitHub ]# File 'activesupport/lib/active_support/dependencies.rb', line 582
def clear! @store.clear end
#get(key) Also known as: #[]
[ GitHub ]# File 'activesupport/lib/active_support/dependencies.rb', line 564
def get(key) key = key.name if key.respond_to?(:name) @store[key] ||= Inflector.constantize(key) end
#key?(key) ⇒ Boolean
# File 'activesupport/lib/active_support/dependencies.rb', line 560
def key?(key) @store.key?(key) end
#safe_get(key)
[ GitHub ]# File 'activesupport/lib/active_support/dependencies.rb', line 570
def safe_get(key) key = key.name if key.respond_to?(:name) @store[key] ||= Inflector.safe_constantize(key) end
#store(klass)
# File 'activesupport/lib/active_support/dependencies.rb', line 575
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