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.
622 623 624 |
# File 'lib/active_support/dependencies.rb', line 622 def initialize @store = Concurrent::Map.new end |
Instance Method Details
#clear! ⇒ Object
652 653 654 |
# File 'lib/active_support/dependencies.rb', line 652 def clear! @store.clear end |
#empty? ⇒ Boolean
626 627 628 |
# File 'lib/active_support/dependencies.rb', line 626 def empty? @store.empty? end |
#get(key) ⇒ Object Also known as: []
634 635 636 637 |
# File 'lib/active_support/dependencies.rb', line 634 def get(key) key = key.name if key.respond_to?(:name) @store[key] ||= Inflector.constantize(key) end |
#key?(key) ⇒ Boolean
630 631 632 |
# File 'lib/active_support/dependencies.rb', line 630 def key?(key) @store.key?(key) end |
#safe_get(key) ⇒ Object
640 641 642 643 |
# File 'lib/active_support/dependencies.rb', line 640 def safe_get(key) key = key.name if key.respond_to?(:name) @store[key] ||= Inflector.safe_constantize(key) end |
#store(klass) ⇒ Object
645 646 647 648 649 650 |
# File 'lib/active_support/dependencies.rb', line 645 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 |