Module: ShardAdapter

Includes:
TSVAdapter
Defined in:
lib/scout/persist/tsv/adapter/sharder.rb

Constant Summary

Constants included from TSVAdapter

TSVAdapter::ANNOTATION_ATTR_HASH_KEY, TSVAdapter::ANNOTATION_ATTR_HASH_SERIALIZER, TSVAdapter::MAX_CHAR, TSVAdapter::SERIALIZER_ALIAS

Instance Attribute Summary

Attributes included from TSVAdapter

#closed, #persistence_class, #persistence_path, #serializer, #writable

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TSVAdapter

#[], #[]=, #close, #closed?, #collect, #delete, #each_annotation_hash_key, #get_prefix, #keys_annotation_hash_key, #load_value, #lock, #lock_and_close, #merge!, #orig_get, #orig_set, #range, #read, #read?, #read_and_close, #read_lock, #save_value, serializer_module, #size_annotation_hash_key, #values, #values_at, #with_read, #with_write, #write, #write?, #write_and_close, #write_and_read, #write_lock

Class Method Details

.extended(obj) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/scout/persist/tsv/adapter/sharder.rb', line 7

def self.extended(obj)
  obj.extend TSVAdapter
  class << obj
    alias keys orig_keys
    alias each orig_each
  end

  obj
end

Instance Method Details

#include?(key) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/scout/persist/tsv/adapter/sharder.rb', line 41

def include?(key)
  self[key] != nil
end

#keysObject



33
34
35
# File 'lib/scout/persist/tsv/adapter/sharder.rb', line 33

def keys
  databases.values.inject([]){|acc,d| acc.concat(d.keys); acc }
end

#load_annotation_hashObject



21
22
23
# File 'lib/scout/persist/tsv/adapter/sharder.rb', line 21

def load_annotation_hash
  ANNOTATION_ATTR_HASH_SERIALIZER.load(Open.read(, mode: 'rb'))
end

#metadata_fileObject



17
18
19
# File 'lib/scout/persist/tsv/adapter/sharder.rb', line 17

def 
  @metadata_file ||= File.join(self.persistence_path, 'metadata')
end

#prefixObject



37
38
39
# File 'lib/scout/persist/tsv/adapter/sharder.rb', line 37

def prefix(...)
  databases.values.inject([]){|acc,d| acc.concat(d.prefix(...)); acc }
end

#save_annotation_hashObject



25
26
27
# File 'lib/scout/persist/tsv/adapter/sharder.rb', line 25

def save_annotation_hash
  Open.write(, ANNOTATION_ATTR_HASH_SERIALIZER.dump(self.annotation_hash), mode: 'wb')
end

#sizeObject



29
30
31
# File 'lib/scout/persist/tsv/adapter/sharder.rb', line 29

def size
  databases.values.inject(0){|acc,d| acc += d.size }
end