Class: ActiveSupport::Dependencies::ClassCache
- Defined in:
- activesupport/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.
608 609 610 |
# File 'activesupport/lib/active_support/dependencies.rb', line 608 def initialize @store = Concurrent::Map.new end |
Instance Method Details
#clear! ⇒ Object
638 639 640 |
# File 'activesupport/lib/active_support/dependencies.rb', line 638 def clear! @store.clear end |
#empty? ⇒ Boolean
612 613 614 |
# File 'activesupport/lib/active_support/dependencies.rb', line 612 def empty? @store.empty? end |
#get(key) ⇒ Object Also known as: []
620 621 622 623 |
# File 'activesupport/lib/active_support/dependencies.rb', line 620 def get(key) key = key.name if key.respond_to?(:name) @store[key] ||= Inflector.constantize(key) end |
#key?(key) ⇒ Boolean
616 617 618 |
# File 'activesupport/lib/active_support/dependencies.rb', line 616 def key?(key) @store.key?(key) end |
#safe_get(key) ⇒ Object
626 627 628 629 |
# File 'activesupport/lib/active_support/dependencies.rb', line 626 def safe_get(key) key = key.name if key.respond_to?(:name) @store[key] ||= Inflector.safe_constantize(key) end |
#store(klass) ⇒ Object
631 632 633 634 635 636 |
# File 'activesupport/lib/active_support/dependencies.rb', line 631 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 |