Class: Aggro::FileStore
- Inherits:
-
Object
- Object
- Aggro::FileStore
- Defined in:
- lib/aggro/file_store.rb,
lib/aggro/file_store/reader.rb,
lib/aggro/file_store/writer.rb
Overview
Public: Stores and retrieves events by serializing them to flat files.
Defined Under Namespace
Constant Summary collapse
- INDEX_DIRECTORY =
'indexes'.freeze
- EVENT_DIRECTORY =
'events'.freeze
- REGISTRY_FILE =
'registry'.freeze
Instance Method Summary collapse
- #all ⇒ Object
- #create(id, type) ⇒ Object
- #exists?(id) ⇒ Boolean
-
#initialize(directory) ⇒ FileStore
constructor
A new instance of FileStore.
- #read(ids) ⇒ Object
- #registry ⇒ Object
- #write(event_streams) ⇒ Object
- #write_single(id, event) ⇒ Object
Constructor Details
#initialize(directory) ⇒ FileStore
Returns a new instance of FileStore.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/aggro/file_store.rb', line 11 def initialize(directory) @event_directory = [directory, EVENT_DIRECTORY].join('/') @index_directory = [directory, INDEX_DIRECTORY].join('/') FileUtils.mkdir_p @event_directory FileUtils.mkdir_p @index_directory @registry_file = [directory, REGISTRY_FILE].join('/') initialize_registry if File.exist? @registry_file end |
Instance Method Details
#all ⇒ Object
22 23 24 |
# File 'lib/aggro/file_store.rb', line 22 def all read registry.keys end |
#create(id, type) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/aggro/file_store.rb', line 26 def create(id, type) File.open(@registry_file, 'ab') do |registry_file| registry_file.write Marshal.dump [id, type] registry[id] = type end self end |
#exists?(id) ⇒ Boolean
35 36 37 |
# File 'lib/aggro/file_store.rb', line 35 def exists?(id) registry[id] == true end |
#read(ids) ⇒ Object
39 40 41 |
# File 'lib/aggro/file_store.rb', line 39 def read(ids) ids.map { |id| id_to_event_stream id } end |
#registry ⇒ Object
43 44 45 |
# File 'lib/aggro/file_store.rb', line 43 def registry @registry ||= {} end |