Class: ApprovalEngine::Configuration

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

Overview

Host-tunable configuration. Every knob here is a seam: the engine ships a sensible default and lets the host application override behaviour without the engine having to know anything about the host’s domain.

ApprovalEngine.configure do |config|
  config.outbox_queue          = :high_priority
  config.actor_class           = "User"
  config.current_tenant_method = -> { Current. }
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



29
30
31
32
33
34
# File 'lib/approval_engine/configuration.rb', line 29

def initialize
  @outbox_queue          = :default
  @current_tenant_method = nil
  @actor_class           = "User"
  @raise_on_rule_errors  = false
end

Instance Attribute Details

#actor_classObject

Name of the host’s actor class (the thing that approves). It must respond to ‘resolve_approval_group(group_name, target)`. Kept as a String so the engine never holds a reference to an un-reloadable constant in development.



22
23
24
# File 'lib/approval_engine/configuration.rb', line 22

def actor_class
  @actor_class
end

#current_tenant_methodObject

A callable (lambda/proc) that returns the current tenant, e.g. ‘-> { Current.account }`. The engine only ever reads `#id` off the result.



14
15
16
# File 'lib/approval_engine/configuration.rb', line 14

def current_tenant_method
  @current_tenant_method
end

#outbox_queueObject

The ActiveJob queue the transactional outbox is processed on.



17
18
19
# File 'lib/approval_engine/configuration.rb', line 17

def outbox_queue
  @outbox_queue
end

#raise_on_rule_errorsObject

When a dynamic rule blows up (e.g. a typo’d payload key), the engine fails closed by quarantining the approval rather than raising into your app. Flip this to ‘true` in development/test to surface the error loudly instead.



27
28
29
# File 'lib/approval_engine/configuration.rb', line 27

def raise_on_rule_errors
  @raise_on_rule_errors
end

Instance Method Details

#actor_class_constantObject

The host’s actor class, resolved lazily so reloading works in development.



37
38
39
# File 'lib/approval_engine/configuration.rb', line 37

def actor_class_constant
  actor_class.to_s.constantize
end

#current_tenantObject

Resolves the current tenant via the configured callable. Returns nil when the host has not configured tenancy (single-tenant apps are welcome too).



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

def current_tenant
  current_tenant_method&.call
end