Class: PatientHttp::PayloadStore::Base
- Inherits:
-
Object
- Object
- PatientHttp::PayloadStore::Base
- Defined in:
- lib/patient_http/payload_store/base.rb
Overview
Abstract base class for payload stores.
Payload stores provide external storage for Request and Response objects that exceed the configured size threshold. This keeps job arguments small while allowing large payloads to be processed.
Subclasses must implement the abstract methods: store, fetch, and delete.
Direct Known Subclasses
Class Method Summary collapse
-
.create(name, **options) ⇒ Base
Create a new store instance from a registered adapter.
-
.lookup(name) ⇒ Class?
Look up a registered adapter by name.
-
.register(name, klass) ⇒ void
Register a payload store adapter.
-
.registered_adapters ⇒ Array<Symbol>
List all registered adapter names.
Instance Method Summary collapse
-
#delete(key) ⇒ Boolean
Delete data by key.
-
#fetch(key) ⇒ Hash?
Fetch data by key.
-
#generate_key ⇒ String
Generate a unique key for storing data.
-
#store(key, data) ⇒ String
Store data with the given key.
-
#store_json(key, json) ⇒ String
Store pre-serialized JSON data with the given key.
Class Method Details
.create(name, **options) ⇒ Base
Create a new store instance from a registered adapter.
71 72 73 74 75 76 |
# File 'lib/patient_http/payload_store/base.rb', line 71 def create(name, **) klass = lookup(name) raise ArgumentError, "Unknown payload store adapter: #{name.inspect}" unless klass klass.new(**) end |
.lookup(name) ⇒ Class?
Look up a registered adapter by name.
59 60 61 62 63 |
# File 'lib/patient_http/payload_store/base.rb', line 59 def lookup(name) registry_mutex.synchronize do registry[name.to_sym] end end |
.register(name, klass) ⇒ void
This method returns an undefined value.
Register a payload store adapter.
49 50 51 52 53 |
# File 'lib/patient_http/payload_store/base.rb', line 49 def register(name, klass) registry_mutex.synchronize do registry[name.to_sym] = klass end end |
.registered_adapters ⇒ Array<Symbol>
List all registered adapter names.
81 82 83 84 85 |
# File 'lib/patient_http/payload_store/base.rb', line 81 def registered_adapters registry_mutex.synchronize do registry.keys end end |
Instance Method Details
#delete(key) ⇒ Boolean
Delete data by key.
This method should be idempotent - deleting a non-existent key should not raise an error.
138 139 140 |
# File 'lib/patient_http/payload_store/base.rb', line 138 def delete(key) raise NotImplementedError, "#{self.class.name} must implement #delete" end |
#fetch(key) ⇒ Hash?
Fetch data by key.
126 127 128 |
# File 'lib/patient_http/payload_store/base.rb', line 126 def fetch(key) raise NotImplementedError, "#{self.class.name} must implement #fetch" end |
#generate_key ⇒ String
Generate a unique key for storing data.
145 146 147 |
# File 'lib/patient_http/payload_store/base.rb', line 145 def generate_key SecureRandom.uuid end |
#store(key, data) ⇒ String
Store data with the given key.
103 104 105 106 |
# File 'lib/patient_http/payload_store/base.rb', line 103 def store(key, data) json = JSON.generate(data) store_json(key, json) end |
#store_json(key, json) ⇒ String
Store pre-serialized JSON data with the given key.
Subclasses that serialize in #store should override this to write the string directly, avoiding double serialization.
117 118 119 |
# File 'lib/patient_http/payload_store/base.rb', line 117 def store_json(key, json) raise NotImplementedError, "#{self.class.name} must implement #store_json" end |