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.
538 539 540 |
# File 'activesupport/lib/active_support/dependencies.rb', line 538 def initialize @store = ThreadSafe::Cache.new end |
Instance Method Details
#clear! ⇒ Object
568 569 570 |
# File 'activesupport/lib/active_support/dependencies.rb', line 568 def clear! @store.clear end |
#empty? ⇒ Boolean
542 543 544 |
# File 'activesupport/lib/active_support/dependencies.rb', line 542 def empty? @store.empty? end |
#get(key) ⇒ Object Also known as: []
550 551 552 553 |
# File 'activesupport/lib/active_support/dependencies.rb', line 550 def get(key) key = key.name if key.respond_to?(:name) @store[key] ||= Inflector.constantize(key) end |
#key?(key) ⇒ Boolean
546 547 548 |
# File 'activesupport/lib/active_support/dependencies.rb', line 546 def key?(key) @store.key?(key) end |
#safe_get(key) ⇒ Object
556 557 558 559 |
# File 'activesupport/lib/active_support/dependencies.rb', line 556 def safe_get(key) key = key.name if key.respond_to?(:name) @store[key] ||= Inflector.safe_constantize(key) end |
#store(klass) ⇒ Object
561 562 563 564 565 566 |
# File 'activesupport/lib/active_support/dependencies.rb', line 561 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 |