Class: S3arch::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/s3arch/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/s3arch/configuration.rb', line 9

def initialize
  @owner_key = 'user_id'
  @searchable_fields = %w[name description]
  @metadata_fields = %w[status created_at]
  @record_filter = ->(_record) { true }
  @owner_extractor = ->(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_mbObject

Returns the value of attribute ephemeral_storage_mb.



5
6
7
# File 'lib/s3arch/configuration.rb', line 5

def ephemeral_storage_mb
  @ephemeral_storage_mb
end

#index_bucketObject

Returns the value of attribute index_bucket.



5
6
7
# File 'lib/s3arch/configuration.rb', line 5

def index_bucket
  @index_bucket
end

#loggerObject

Returns the value of attribute logger.



5
6
7
# File 'lib/s3arch/configuration.rb', line 5

def logger
  @logger
end

#max_cached_dbsObject

Returns the value of attribute max_cached_dbs.



5
6
7
# File 'lib/s3arch/configuration.rb', line 5

def max_cached_dbs
  @max_cached_dbs
end

#max_resultsObject

Returns the value of attribute max_results.



5
6
7
# File 'lib/s3arch/configuration.rb', line 5

def max_results
  @max_results
end

#metadata_fieldsObject

Returns the value of attribute metadata_fields.



5
6
7
# File 'lib/s3arch/configuration.rb', line 5

def 
  @metadata_fields
end

#owner_extractorObject

Returns the value of attribute owner_extractor.



5
6
7
# File 'lib/s3arch/configuration.rb', line 5

def owner_extractor
  @owner_extractor
end

#owner_keyObject

Returns the value of attribute owner_key.



5
6
7
# File 'lib/s3arch/configuration.rb', line 5

def owner_key
  @owner_key
end

#record_filterObject

Returns the value of attribute record_filter.



5
6
7
# File 'lib/s3arch/configuration.rb', line 5

def record_filter
  @record_filter
end

#searchable_fieldsObject

Returns the value of attribute searchable_fields.



5
6
7
# File 'lib/s3arch/configuration.rb', line 5

def searchable_fields
  @searchable_fields
end

#source_indexObject

Returns the value of attribute source_index.



5
6
7
# File 'lib/s3arch/configuration.rb', line 5

def source_index
  @source_index
end

#source_tableObject

Returns the value of attribute source_table.



5
6
7
# File 'lib/s3arch/configuration.rb', line 5

def source_table
  @source_table
end

#version_tableObject

Returns the value of attribute version_table.



5
6
7
# File 'lib/s3arch/configuration.rb', line 5

def version_table
  @version_table
end

#version_ttlObject

Returns the value of attribute version_ttl.



5
6
7
# File 'lib/s3arch/configuration.rb', line 5

def version_ttl
  @version_ttl
end

Instance Method Details

#from_env!Object



25
26
27
28
29
30
31
# File 'lib/s3arch/configuration.rb', line 25

def from_env!
  @source_table = ENV['S3ARCH_SOURCE_TABLE']
  @source_index = ENV['S3ARCH_SOURCE_INDEX'] || 'UserIndex'
  @index_bucket = ENV['S3ARCH_INDEX_BUCKET']
  @version_table = ENV['S3ARCH_VERSION_TABLE']
  self
end

#validate!Object

Raises:



33
34
35
36
37
38
39
40
# File 'lib/s3arch/configuration.rb', line 33

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