Class: Prescient::DocumentSource::RedisJson
- Defined in:
- lib/prescient/document_source.rb
Overview
Read JSON documents from a Redis-compatible client. The client is injected to keep Redis optional for gem consumers.
Instance Method Summary collapse
-
#fetch ⇒ Array<Hash>
Documents loaded from Redis.
-
#initialize(client:, key:, **options) ⇒ RedisJson
constructor
A new instance of RedisJson.
Constructor Details
#initialize(client:, key:, **options) ⇒ RedisJson
Returns a new instance of RedisJson.
94 95 96 97 98 99 100 101 |
# File 'lib/prescient/document_source.rb', line 94 def initialize(client:, key:, **) super(**) @client = client @key = key return if @key.is_a?(String) && !@key.empty? raise Prescient::Error, "Redis document key must be a non-empty string" end |
Instance Method Details
#fetch ⇒ Array<Hash>
Returns Documents loaded from Redis.
104 105 106 107 108 109 110 111 |
# File 'lib/prescient/document_source.rb', line 104 def fetch value = @client.get(@key) raise Prescient::Error, "Redis document source key not found: #{@key}" unless value parse_json(value) rescue NoMethodError raise Prescient::Error, "Redis document source client must provide get" end |