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.
521 522 523 |
# File 'lib/active_support/dependencies.rb', line 521 def initialize @store = ThreadSafe::Cache.new end |
Instance Method Details
#clear! ⇒ Object
551 552 553 |
# File 'lib/active_support/dependencies.rb', line 551 def clear! @store.clear end |
#empty? ⇒ Boolean
525 526 527 |
# File 'lib/active_support/dependencies.rb', line 525 def empty? @store.empty? end |
#get(key) ⇒ Object Also known as: []
533 534 535 536 |
# File 'lib/active_support/dependencies.rb', line 533 def get(key) key = key.name if key.respond_to?(:name) @store[key] ||= Inflector.constantize(key) end |
#key?(key) ⇒ Boolean
529 530 531 |
# File 'lib/active_support/dependencies.rb', line 529 def key?(key) @store.key?(key) end |
#safe_get(key) ⇒ Object
539 540 541 542 |
# File 'lib/active_support/dependencies.rb', line 539 def safe_get(key) key = key.name if key.respond_to?(:name) @store[key] ||= Inflector.safe_constantize(key) end |
#store(klass) ⇒ Object
544 545 546 547 548 549 |
# File 'lib/active_support/dependencies.rb', line 544 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 |