Class: SchemaSherlock::BinaryIndex
- Inherits:
-
Object
- Object
- SchemaSherlock::BinaryIndex
- Defined in:
- lib/schema_sherlock/binary_index.rb
Constant Summary collapse
- INDEX_VERSION =
"1.0"
- INDEX_FILE =
"tmp/.schema_sherlock_index"
Class Method Summary collapse
- .build_and_save_index(root_path, index_path) ⇒ Object
- .load_index(path) ⇒ Object
- .load_or_build(root_path) ⇒ Object
Class Method Details
.build_and_save_index(root_path, index_path) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/schema_sherlock/binary_index.rb', line 28 def build_and_save_index(root_path, index_path) index = build_index(root_path) # Binary serialization packed_data = MessagePack.pack(index) File.binwrite(index_path, packed_data) index rescue => e Rails.logger.warn("Failed to save index: #{e.}") if defined?(Rails) index end |
.load_index(path) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/schema_sherlock/binary_index.rb', line 20 def load_index(path) data = File.binread(path) MessagePack.unpack(data, symbolize_keys: true) rescue => e Rails.logger.warn("Failed to load index: #{e.}") if defined?(Rails) nil end |
.load_or_build(root_path) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/schema_sherlock/binary_index.rb', line 10 def load_or_build(root_path) index_path = File.join(root_path, INDEX_FILE) if File.exist?(index_path) && index_valid?(index_path, root_path) load_index(index_path) else build_and_save_index(root_path, index_path) end end |