Class: Fractor::QueuePersister::MarshalPersister
- Defined in:
- lib/fractor/queue_persister.rb
Overview
Marshal file persister. Uses Ruby's Marshal for binary serialization. Note: Marshal is not secure and should not be used with untrusted data.
Instance Method Summary collapse
-
#clear ⇒ Boolean
Clear the Marshal file.
-
#initialize(path) ⇒ MarshalPersister
constructor
Initialize a Marshal persister.
-
#load ⇒ Array<Hash>?
Load work items using Marshal.
-
#save(items) ⇒ Boolean
Save work items using Marshal.
Constructor Details
#initialize(path) ⇒ MarshalPersister
Initialize a Marshal persister.
197 198 199 |
# File 'lib/fractor/queue_persister.rb', line 197 def initialize(path) @path = path end |
Instance Method Details
#clear ⇒ Boolean
Clear the Marshal file.
234 235 236 237 238 239 240 |
# File 'lib/fractor/queue_persister.rb', line 234 def clear File.delete(@path) if File.exist?(@path) true rescue StandardError => e warn "Failed to clear #{@path}: #{e.}" false end |
#load ⇒ Array<Hash>?
Load work items using Marshal.
221 222 223 224 225 226 227 228 229 |
# File 'lib/fractor/queue_persister.rb', line 221 def load return nil unless File.exist?(@path) data = File.binread(@path) Marshal.load(data) rescue StandardError => e warn "Failed to load from #{@path}: #{e.}" nil end |
#save(items) ⇒ Boolean
Save work items using Marshal.
205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/fractor/queue_persister.rb', line 205 def save(items) ensure_directory_exists serialized = items.map { |work| serialize_work(work) } data = Marshal.dump(serialized) File.binwrite(@path, data) true rescue StandardError => e warn "Failed to save to #{@path}: #{e.}" false end |