Class: Whodunit::Chronicles::Configuration
- Inherits:
-
Object
- Object
- Whodunit::Chronicles::Configuration
- Defined in:
- lib/whodunit/chronicles/configuration.rb
Overview
Configuration management for Chronicles
Provides a centralized configuration system with sensible defaults and validation for all Chronicles settings.
Instance Attribute Summary collapse
-
#adapter ⇒ Object
Returns the value of attribute adapter.
-
#audit_database_url ⇒ Object
Returns the value of attribute audit_database_url.
-
#batch_size ⇒ Object
Returns the value of attribute batch_size.
-
#database_url ⇒ Object
Returns the value of attribute database_url.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#max_retry_attempts ⇒ Object
Returns the value of attribute max_retry_attempts.
-
#publication_name ⇒ Object
Returns the value of attribute publication_name.
-
#replication_slot_name ⇒ Object
Returns the value of attribute replication_slot_name.
-
#retry_delay ⇒ Object
Returns the value of attribute retry_delay.
-
#schema_filter ⇒ Object
Returns the value of attribute schema_filter.
-
#table_filter ⇒ Object
Returns the value of attribute table_filter.
Instance Method Summary collapse
-
#audit_table?(table_name, schema_name = 'public') ⇒ Boolean
Check if a table should be audited based on filters.
-
#filtered_by_schema?(schema_name) ⇒ Boolean
private
-
#filtered_by_table?(table_name) ⇒ Boolean
private
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#validate! ⇒ Object
Validate configuration settings.
-
#validate_publication_name! ⇒ Object
private
-
#validate_slot_name! ⇒ Object
private
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/whodunit/chronicles/configuration.rb', line 14 def initialize @database_url = ENV.fetch('DATABASE_URL', nil) @audit_database_url = ENV.fetch('AUDIT_DATABASE_URL', nil) @adapter = :postgresql @publication_name = 'whodunit_audit' @replication_slot_name = 'whodunit_audit_slot' @batch_size = 100 @max_retry_attempts = 3 @retry_delay = 5 @logger = Dry::Logger.new @table_filter = nil @schema_filter = nil end |
Instance Attribute Details
#adapter ⇒ Object
Returns the value of attribute adapter.
10 11 12 |
# File 'lib/whodunit/chronicles/configuration.rb', line 10 def adapter @adapter end |
#audit_database_url ⇒ Object
Returns the value of attribute audit_database_url.
10 11 12 |
# File 'lib/whodunit/chronicles/configuration.rb', line 10 def audit_database_url @audit_database_url end |
#batch_size ⇒ Object
Returns the value of attribute batch_size.
10 11 12 |
# File 'lib/whodunit/chronicles/configuration.rb', line 10 def batch_size @batch_size end |
#database_url ⇒ Object
Returns the value of attribute database_url.
10 11 12 |
# File 'lib/whodunit/chronicles/configuration.rb', line 10 def database_url @database_url end |
#logger ⇒ Object
Returns the value of attribute logger.
10 11 12 |
# File 'lib/whodunit/chronicles/configuration.rb', line 10 def logger @logger end |
#max_retry_attempts ⇒ Object
Returns the value of attribute max_retry_attempts.
10 11 12 |
# File 'lib/whodunit/chronicles/configuration.rb', line 10 def max_retry_attempts @max_retry_attempts end |
#publication_name ⇒ Object
Returns the value of attribute publication_name.
10 11 12 |
# File 'lib/whodunit/chronicles/configuration.rb', line 10 def publication_name @publication_name end |
#replication_slot_name ⇒ Object
Returns the value of attribute replication_slot_name.
10 11 12 |
# File 'lib/whodunit/chronicles/configuration.rb', line 10 def replication_slot_name @replication_slot_name end |
#retry_delay ⇒ Object
Returns the value of attribute retry_delay.
10 11 12 |
# File 'lib/whodunit/chronicles/configuration.rb', line 10 def retry_delay @retry_delay end |
#schema_filter ⇒ Object
Returns the value of attribute schema_filter.
10 11 12 |
# File 'lib/whodunit/chronicles/configuration.rb', line 10 def schema_filter @schema_filter end |
#table_filter ⇒ Object
Returns the value of attribute table_filter.
10 11 12 |
# File 'lib/whodunit/chronicles/configuration.rb', line 10 def table_filter @table_filter end |
Instance Method Details
#audit_table?(table_name, schema_name = 'public') ⇒ Boolean
Check if a table should be audited based on filters
47 48 49 50 51 52 |
# File 'lib/whodunit/chronicles/configuration.rb', line 47 def audit_table?(table_name, schema_name = 'public') return false if filtered_by_schema?(schema_name) return false if filtered_by_table?(table_name) true end |
#filtered_by_schema?(schema_name) ⇒ Boolean (private)
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/whodunit/chronicles/configuration.rb', line 68 def filtered_by_schema?(schema_name) return false unless schema_filter case schema_filter when Array !schema_filter.include?(schema_name) when String, Symbol schema_name != schema_filter.to_s when Proc !schema_filter.call(schema_name) else false end end |
#filtered_by_table?(table_name) ⇒ Boolean (private)
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/whodunit/chronicles/configuration.rb', line 83 def filtered_by_table?(table_name) return false unless table_filter case table_filter when Array !table_filter.include?(table_name) when String, Symbol table_name != table_filter.to_s when Regexp !table_filter.match?(table_name) when Proc !table_filter.call(table_name) else false end end |
#validate! ⇒ Object
Validate configuration settings
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/whodunit/chronicles/configuration.rb', line 31 def validate! raise ConfigurationError, 'database_url is required' if database_url.nil? raise ConfigurationError, 'adapter must be :postgresql' unless adapter == :postgresql raise ConfigurationError, 'batch_size must be positive' unless batch_size.positive? raise ConfigurationError, 'max_retry_attempts must be positive' unless max_retry_attempts.positive? raise ConfigurationError, 'retry_delay must be positive' unless retry_delay.positive? validate_publication_name! validate_slot_name! end |
#validate_publication_name! ⇒ Object (private)
56 57 58 59 60 |
# File 'lib/whodunit/chronicles/configuration.rb', line 56 def validate_publication_name! return if /\A[a-zA-Z_][a-zA-Z0-9_]*\z/.match?(publication_name) raise ConfigurationError, 'publication_name must be a valid PostgreSQL identifier' end |
#validate_slot_name! ⇒ Object (private)
62 63 64 65 66 |
# File 'lib/whodunit/chronicles/configuration.rb', line 62 def validate_slot_name! return if /\A[a-zA-Z_][a-zA-Z0-9_]*\z/.match?(replication_slot_name) raise ConfigurationError, 'replication_slot_name must be a valid PostgreSQL identifier' end |