Class: S3arch::Configuration
- Inherits:
-
Object
- Object
- S3arch::Configuration
- Defined in:
- lib/s3arch/configuration.rb
Instance Attribute Summary collapse
-
#ephemeral_storage_mb ⇒ Object
Searcher settings.
-
#index_bucket ⇒ Object
S3 bucket for storing SQLite index files.
-
#logger ⇒ Object
Logger (defaults to $stdout).
-
#max_cached_dbs ⇒ Object
Searcher settings.
-
#max_results ⇒ Object
Searcher settings.
-
#metadata_fields ⇒ Object
Metadata fields stored alongside FTS5 for filtering (not searched).
-
#owner_extractor ⇒ Object
Owner extractor — proc that extracts owner_id from a DynamoDB stream record.
-
#owner_key ⇒ Object
Partition key field on the source table for owner lookup.
-
#record_filter ⇒ Object
Filter proc — receives a record hash, returns true to include in index.
-
#searchable_fields ⇒ Object
FTS5 searchable fields — array of field names from the source record.
-
#source_index ⇒ Object
DynamoDB index to query records by owner (e.g., ‘UserIndex’).
-
#source_table ⇒ Object
DynamoDB table that contains the source records to index.
-
#token_field ⇒ Object
DynamoDB attribute name where pre-computed tokens are stored (Map type) e.g., { “searchTokens”: { “name”: “blue jacket”, “description”: “warm winter coat” } }.
-
#version_table ⇒ Object
DynamoDB table for version tracking.
-
#version_ttl ⇒ Object
Searcher settings.
Instance Method Summary collapse
-
#from_env! ⇒ Object
Convenience: env-based configuration (reads from Lambda environment variables).
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #validate! ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/s3arch/configuration.rb', line 42 def initialize @owner_key = 'user_id' @searchable_fields = %w[name description] @token_field = 'searchTokens' @metadata_fields = %w[status created_at] @record_filter = ->(_record) { true } @owner_extractor = lambda { |stream_record| image = stream_record.dig('dynamodb', 'NewImage') || stream_record.dig('dynamodb', 'OldImage') || {} image.dig(owner_key, 'S') } @version_ttl = 30 @max_results = 50 @max_cached_dbs = 20 @ephemeral_storage_mb = 2048 @logger = nil end |
Instance Attribute Details
#ephemeral_storage_mb ⇒ Object
Searcher settings
40 41 42 |
# File 'lib/s3arch/configuration.rb', line 40 def ephemeral_storage_mb @ephemeral_storage_mb end |
#index_bucket ⇒ Object
S3 bucket for storing SQLite index files
15 16 17 |
# File 'lib/s3arch/configuration.rb', line 15 def index_bucket @index_bucket end |
#logger ⇒ Object
Logger (defaults to $stdout)
37 38 39 |
# File 'lib/s3arch/configuration.rb', line 37 def logger @logger end |
#max_cached_dbs ⇒ Object
Searcher settings
40 41 42 |
# File 'lib/s3arch/configuration.rb', line 40 def max_cached_dbs @max_cached_dbs end |
#max_results ⇒ Object
Searcher settings
40 41 42 |
# File 'lib/s3arch/configuration.rb', line 40 def max_results @max_results end |
#metadata_fields ⇒ Object
Metadata fields stored alongside FTS5 for filtering (not searched)
28 29 30 |
# File 'lib/s3arch/configuration.rb', line 28 def @metadata_fields end |
#owner_extractor ⇒ Object
Owner extractor — proc that extracts owner_id from a DynamoDB stream record
34 35 36 |
# File 'lib/s3arch/configuration.rb', line 34 def owner_extractor @owner_extractor end |
#owner_key ⇒ Object
Partition key field on the source table for owner lookup
12 13 14 |
# File 'lib/s3arch/configuration.rb', line 12 def owner_key @owner_key end |
#record_filter ⇒ Object
Filter proc — receives a record hash, returns true to include in index
31 32 33 |
# File 'lib/s3arch/configuration.rb', line 31 def record_filter @record_filter end |
#searchable_fields ⇒ Object
FTS5 searchable fields — array of field names from the source record
21 22 23 |
# File 'lib/s3arch/configuration.rb', line 21 def searchable_fields @searchable_fields end |
#source_index ⇒ Object
DynamoDB index to query records by owner (e.g., ‘UserIndex’)
9 10 11 |
# File 'lib/s3arch/configuration.rb', line 9 def source_index @source_index end |
#source_table ⇒ Object
DynamoDB table that contains the source records to index
6 7 8 |
# File 'lib/s3arch/configuration.rb', line 6 def source_table @source_table end |
#token_field ⇒ Object
DynamoDB attribute name where pre-computed tokens are stored (Map type) e.g., { “searchTokens”: { “name”: “blue jacket”, “description”: “warm winter coat” } }
25 26 27 |
# File 'lib/s3arch/configuration.rb', line 25 def token_field @token_field end |
#version_table ⇒ Object
DynamoDB table for version tracking
18 19 20 |
# File 'lib/s3arch/configuration.rb', line 18 def version_table @version_table end |
#version_ttl ⇒ Object
Searcher settings
40 41 42 |
# File 'lib/s3arch/configuration.rb', line 40 def version_ttl @version_ttl end |
Instance Method Details
#from_env! ⇒ Object
Convenience: env-based configuration (reads from Lambda environment variables)
60 61 62 63 64 65 66 |
# File 'lib/s3arch/configuration.rb', line 60 def from_env! @source_table = ENV['S3ARCH_SOURCE_TABLE'] || ENV.fetch('INVENTORY_TABLE', nil) @source_index = ENV['S3ARCH_SOURCE_INDEX'] || 'UserIndex' @index_bucket = ENV['S3ARCH_INDEX_BUCKET'] || ENV.fetch('SEARCH_INDEX_BUCKET', nil) @version_table = ENV['S3ARCH_VERSION_TABLE'] || ENV.fetch('SEARCH_INDEX_TABLE', nil) self end |
#validate! ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/s3arch/configuration.rb', line 68 def validate! missing = [] missing << 'source_table' unless source_table missing << 'index_bucket' unless index_bucket missing << 'version_table' unless version_table missing << 'source_index' unless source_index raise Error, "S3arch configuration missing: #{missing.join(', ')}" if missing.any? end |