Module: DS::Source::SourceCache
- Included in:
- BaseSource
- Defined in:
- lib/ds/source/source_cache.rb
Overview
This module provides methods for caching and opening source files. It is used by the DS::Mapper::BaseMapper class.
It makes available a #find_or_open_source method that can be used by the including class to open or retrieve a parse source file from the cache.
Including classes must implement the open_source method.
The file path is used as the cache key.
The initial cache size is the value of DS::Util::Cache::DEFAULT_MAX_SIZE.
Cache max size can be set and retrieved using the max_cache_size and max_cache_size= methods. #
Instance Method Summary collapse
-
#cache ⇒ DS::Util::Cache
Returns the cache object.
-
#find_or_open_source(source_path) ⇒ Object
Finds or opens a source file at the given path.
-
#max_cache_size ⇒ Integer
Returns the maximum cache size.
-
#max_cache_size=(size) ⇒ void
Sets the maximum cache size.
-
#open_source(source_path) ⇒ Object
Opens a source file at the given path.
Instance Method Details
#cache ⇒ DS::Util::Cache
Returns the cache object.
This method lazily initializes the cache object if it is not already initialized. The cache object is an instance of the DS::Util::Cache class.
49 50 51 |
# File 'lib/ds/source/source_cache.rb', line 49 def cache @cache ||= DS::Util::Cache.new end |
#find_or_open_source(source_path) ⇒ Object
Finds or opens a source file at the given path.
27 28 29 30 31 32 |
# File 'lib/ds/source/source_cache.rb', line 27 def find_or_open_source source_path return cache.get_item source_path if cache.include? source_path source = open_source source_path cache.add source_path, source source end |
#max_cache_size ⇒ Integer
Returns the maximum cache size.
64 65 66 |
# File 'lib/ds/source/source_cache.rb', line 64 def max_cache_size cache.max_size end |
#max_cache_size=(size) ⇒ void
This method returns an undefined value.
Sets the maximum cache size.
57 58 59 |
# File 'lib/ds/source/source_cache.rb', line 57 def max_cache_size= size cache.max_size = size end |
#open_source(source_path) ⇒ Object
Opens a source file at the given path.
39 40 41 |
# File 'lib/ds/source/source_cache.rb', line 39 def open_source source_path raise NotImplementedError end |