Class: EventMeter::Stores::Stream::File
- Inherits:
-
Object
- Object
- EventMeter::Stores::Stream::File
- Includes:
- FileHelpers
- Defined in:
- lib/event_meter/stores/stream/file.rb
Constant Summary collapse
- SYNC_MODES =
%i[none flush fsync].freeze
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#stream_options ⇒ Object
readonly
Returns the value of attribute stream_options.
-
#sync ⇒ Object
readonly
Returns the value of attribute sync.
Instance Method Summary collapse
- #append(payload) ⇒ Object
- #close ⇒ Object
- #delete ⇒ Object
-
#initialize(path:, sync: :flush, **stream_options) ⇒ File
constructor
A new instance of File.
- #read(name:) ⇒ Object
- #release ⇒ Object
Constructor Details
#initialize(path:, sync: :flush, **stream_options) ⇒ File
Returns a new instance of File.
15 16 17 18 19 20 21 22 |
# File 'lib/event_meter/stores/stream/file.rb', line 15 def initialize(path:, sync: :flush, **) @path = normalize_file_store_path(path) @sync = sync.respond_to?(:to_sym) ? sync.to_sym : sync @stream_options = validate_sync! @streams = {} @read_ids = [] end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
13 14 15 |
# File 'lib/event_meter/stores/stream/file.rb', line 13 def path @path end |
#stream_options ⇒ Object (readonly)
Returns the value of attribute stream_options.
13 14 15 |
# File 'lib/event_meter/stores/stream/file.rb', line 13 def @stream_options end |
#sync ⇒ Object (readonly)
Returns the value of attribute sync.
13 14 15 |
# File 'lib/event_meter/stores/stream/file.rb', line 13 def sync @sync end |
Instance Method Details
#append(payload) ⇒ Object
24 25 26 27 |
# File 'lib/event_meter/stores/stream/file.rb', line 24 def append(payload) hash = payload.to_h stream_for(hash.fetch("name")).append(hash) end |
#close ⇒ Object
56 57 58 59 |
# File 'lib/event_meter/stores/stream/file.rb', line 56 def close release @streams.each_value(&:close) end |
#delete ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/event_meter/stores/stream/file.rb', line 37 def delete return false unless @batch @batch.delete deleted_claims? ensure @read_ids = [] @read_name = nil @batch = nil end |
#read(name:) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/event_meter/stores/stream/file.rb', line 29 def read(name:) release @read_name = name.to_s @batch = stream_for(name).read @read_ids = @batch.entries.map(&:first) @batch.entries end |
#release ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/event_meter/stores/stream/file.rb', line 48 def release @batch&.release ensure @read_ids = [] @read_name = nil @batch = nil end |