Class: ActiveSupport::Dependencies::ClassCache
- Defined in:
- lib/active_support/dependencies.rb
Instance Method Summary collapse
- #clear! ⇒ Object
- #empty? ⇒ Boolean
- #get(key) ⇒ Object (also: #[])
-
#initialize ⇒ ClassCache
constructor
A new instance of ClassCache.
- #key?(key) ⇒ Boolean
- #safe_get(key) ⇒ Object
- #store(klass) ⇒ Object
Constructor Details
#initialize ⇒ ClassCache
Returns a new instance of ClassCache.
560 561 562 |
# File 'lib/active_support/dependencies.rb', line 560 def initialize @store = Concurrent::Map.new end |
Instance Method Details
#clear! ⇒ Object
590 591 592 |
# File 'lib/active_support/dependencies.rb', line 590 def clear! @store.clear end |
#empty? ⇒ Boolean
564 565 566 |
# File 'lib/active_support/dependencies.rb', line 564 def empty? @store.empty? end |
#get(key) ⇒ Object Also known as: []
572 573 574 575 |
# File 'lib/active_support/dependencies.rb', line 572 def get(key) key = key.name if key.respond_to?(:name) @store[key] ||= Inflector.constantize(key) end |
#key?(key) ⇒ Boolean
568 569 570 |
# File 'lib/active_support/dependencies.rb', line 568 def key?(key) @store.key?(key) end |
#safe_get(key) ⇒ Object
578 579 580 581 |
# File 'lib/active_support/dependencies.rb', line 578 def safe_get(key) key = key.name if key.respond_to?(:name) @store[key] ||= Inflector.safe_constantize(key) end |
#store(klass) ⇒ Object
583 584 585 586 587 588 |
# File 'lib/active_support/dependencies.rb', line 583 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 |