Module: Documentrix::Documents::Cache::Common
- Includes:
- Utils::Math
- Included in:
- SQLiteCache, MemoryCache, RedisCache
- Defined in:
- lib/documentrix/documents/cache/common.rb
Instance Attribute Summary collapse
-
#prefix ⇒ Object
current prefix defined for the cache.
Instance Method Summary collapse
-
#collections(prefix) ⇒ Array<Symbol>
Returns an array of collection names that match the given prefix.
-
#initialize(prefix:) ⇒ Object
The initialize method sets up the Documentrix::Documents::Cache instance's by setting its prefix attribute to the given value.
-
#pre(key) ⇒ String
Returns a string representing the given
keyprefixed with the defined prefix. -
#unpre(key) ⇒ String
Returns a string with the prefix removed from the given
key.
Methods included from Utils::Math
#convert_to_vector, #cosine_similarity, #norm
Instance Attribute Details
#prefix ⇒ Object
current prefix defined for the cache
12 13 14 |
# File 'lib/documentrix/documents/cache/common.rb', line 12 def prefix @prefix end |
Instance Method Details
#collections(prefix) ⇒ Array<Symbol>
Returns an array of collection names that match the given prefix.
18 19 20 21 22 23 24 25 |
# File 'lib/documentrix/documents/cache/common.rb', line 18 def collections(prefix) unique = Set.new full_each do |key, _| key =~ /\A#{prefix}(.+)-/ or next unique << $1 end unique.map(&:to_sym) end |
#initialize(prefix:) ⇒ Object
The initialize method sets up the Documentrix::Documents::Cache instance's by setting its prefix attribute to the given value.
8 9 10 |
# File 'lib/documentrix/documents/cache/common.rb', line 8 def initialize(prefix:) self.prefix = prefix end |
#pre(key) ⇒ String
Returns a string representing the given key prefixed with the defined
prefix.
32 33 34 |
# File 'lib/documentrix/documents/cache/common.rb', line 32 def pre(key) [ @prefix, key ].join end |
#unpre(key) ⇒ String
Returns a string with the prefix removed from the given key.
40 41 42 |
# File 'lib/documentrix/documents/cache/common.rb', line 40 def unpre(key) key.sub(/\A#@prefix/, '') end |