Class: StandardLedger::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/standard_ledger/config.rb

Overview

Host-configurable settings, populated via ‘StandardLedger.configure { |c| … }` in an initializer. All attributes have sensible defaults; hosts only override what they need.

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



47
48
49
50
51
52
53
54
55
# File 'lib/standard_ledger/config.rb', line 47

def initialize
  @default_async_job        = nil   # resolved lazily to avoid loading the job constant before Rails boots
  @default_async_retries    = 3
  @scheduler                = :solid_queue
  @matview_refresh_strategy = :concurrent
  @result_class             = nil
  @result_adapter           = nil
  @notification_namespace   = "standard_ledger"
end

Instance Attribute Details

#default_async_jobObject

The ActiveJob class used by ‘:async` mode projections. Defaults to `StandardLedger::ProjectionJob`. Hosts can supply their own job class (e.g. for custom queue routing or per-projection telemetry) via `c.default_async_job = Orders::FulfillableProjectionJob`.



12
13
14
# File 'lib/standard_ledger/config.rb', line 12

def default_async_job
  @default_async_job
end

#default_async_retriesObject

Total attempts (including the first) for an ‘:async` projection before the failure is propagated. Default: 3 (one initial run + two retries). Matches ActiveJob’s ‘retry_on attempts:` semantics.



17
18
19
# File 'lib/standard_ledger/config.rb', line 17

def default_async_retries
  @default_async_retries
end

#matview_refresh_strategyObject

Default refresh strategy for ‘:matview` projections. Either `:concurrent` (REFRESH MATERIALIZED VIEW CONCURRENTLY — requires a unique index on the view) or `:blocking`. Default: `:concurrent`.



27
28
29
# File 'lib/standard_ledger/config.rb', line 27

def matview_refresh_strategy
  @matview_refresh_strategy
end

#notification_namespaceObject

Prefix for ‘ActiveSupport::Notifications` events emitted by the gem. Default: `“standard_ledger”`. Events: `<prefix>.entry.created`, `<prefix>.projection.applied`, `<prefix>.projection.failed`, `<prefix>.projection.refreshed`, `<prefix>.projection.rebuilt`.



45
46
47
# File 'lib/standard_ledger/config.rb', line 45

def notification_namespace
  @notification_namespace
end

#result_adapterObject

Optional: a callable that translates the gem’s result fields into the host’s Result type. Receives keyword args: ‘success:, value:, errors:, entry:, idempotent:, projections:`. Required when `result_class` is set.



38
39
40
# File 'lib/standard_ledger/config.rb', line 38

def result_adapter
  @result_adapter
end

#result_classObject

Optional: the host application’s Result class. When set together with ‘result_adapter`, `StandardLedger.post` returns instances of this class instead of `StandardLedger::Result`.



32
33
34
# File 'lib/standard_ledger/config.rb', line 32

def result_class
  @result_class
end

#schedulerObject

Scheduler backend for ‘:matview` refresh jobs. One of `:solid_queue`, `:sidekiq_cron`, `:custom`. Default: `:solid_queue` (matches all four consuming apps).



22
23
24
# File 'lib/standard_ledger/config.rb', line 22

def scheduler
  @scheduler
end

Instance Method Details

#custom_result?Boolean

True when the host has wired up its own Result type. When false, the gem returns its built-in ‘StandardLedger::Result`.

Returns:

  • (Boolean)


59
60
61
# File 'lib/standard_ledger/config.rb', line 59

def custom_result?
  !result_class.nil? && !result_adapter.nil?
end