Class: ActiveStorage::AwsRecord::Configuration

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

Overview

Holds the gem’s settings. In a Rails app these are populated from config.activestorage_aws_record by the Railtie; outside Rails (the gem’s own test suite) they are set directly via configure.

The guiding principle is *assume as little as possible*: the only thing the gem truly needs is the table_name. The partition/sort key attribute names and types are discovered from the live table at boot (see Schema); set #partition_key/#sort_key only to override that discovery.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



51
52
53
54
55
56
57
58
59
# File 'lib/active_storage/aws_record/configuration.rb', line 51

def initialize
  @table_name = 'active_storage'
  @namespace = 'ActiveStorage'
  @separator = '#'
  @client_options = {}
  @client = nil
  @manage_table = false
  @index_name = 'active_storage_index'
end

Instance Attribute Details

#clientObject

An explicit Aws::DynamoDB::Client. When set it is used as-is and client_options is ignored. Handy for tests and dependency injection.



39
40
41
# File 'lib/active_storage/aws_record/configuration.rb', line 39

def client
  @client
end

#client_optionsObject

Hash of options forwarded to Aws::DynamoDB::Client.new (e.g. :region, :endpoint, :credentials). An :endpoint of “localhost:8000” targets DynamoDB Local.



35
36
37
# File 'lib/active_storage/aws_record/configuration.rb', line 35

def client_options
  @client_options
end

#index_nameObject

Name of the string-keyed GSI used only when the table’s range key is numeric (Mode B); identifies which GSI carries the adjacency keys when a table has several. Its key attribute names are auto-detected. Ignored in Mode A (string range key, no GSI).



49
50
51
# File 'lib/active_storage/aws_record/configuration.rb', line 49

def index_name
  @index_name
end

#manage_tableObject

When true, the gem will create the table (and, in Mode B, the index) if missing. Defaults to false: production tables are application-managed.



43
44
45
# File 'lib/active_storage/aws_record/configuration.rb', line 43

def manage_table
  @manage_table
end

#namespaceObject

First segment of every key the gem writes, isolating Active Storage items from the application’s own items in the shared table. Make it unique if the default (“ActiveStorage”) could collide with application keys.



26
27
28
# File 'lib/active_storage/aws_record/configuration.rb', line 26

def namespace
  @namespace
end

#separatorObject

Delimiter between key segments (the “#” pattern). Must not appear in a record_type, record_id, or attachment name.



30
31
32
# File 'lib/active_storage/aws_record/configuration.rb', line 30

def separator
  @separator
end

#table_nameObject

Name of the single DynamoDB table that holds every Active Storage item (blob, attachment, and variant-record metadata). Single Table Design: the gem never creates entity-specific tables. The partition/sort key attribute names and types are auto-detected from this table at boot (see Schema).



21
22
23
# File 'lib/active_storage/aws_record/configuration.rb', line 21

def table_name
  @table_name
end