Class: Signoff::Configuration
- Inherits:
-
Object
- Object
- Signoff::Configuration
- Defined in:
- lib/signoff/configuration.rb
Overview
Instance Attribute Summary collapse
-
#default_state_column ⇒ Object
Default column used to store the current state on workflowable models.
-
#dependent ⇒ Object
:dependentstrategy for the events association. -
#event_table_name ⇒ Object
Physical table name backing Signoff::Event.
-
#immutable_events ⇒ Object
When true (the default) persisted events are read-only: they cannot be updated or destroyed through ActiveRecord, guaranteeing an immutable audit trail.
-
#store_user_agent ⇒ Object
When true, the
user_agentcaptured in Signoff::Current (or passed explicitly) is persisted on every event. -
#track_ip_addresses ⇒ Object
When true, the
ip_addresscaptured in Signoff::Current (or passed explicitly) is persisted on every event. -
#user_class ⇒ Object
String name of the model that represents the acting user.
-
#validate_on_transition ⇒ Object
When true the workflowable record is fully validated before its state column is written.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#user_model ⇒ Object
Resolve the configured user class constant.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/signoff/configuration.rb', line 48 def initialize @user_class = "User" @track_ip_addresses = false @store_user_agent = false @default_state_column = :approval_state @event_table_name = "signoff_events" @validate_on_transition = false @dependent = :delete_all @immutable_events = true end |
Instance Attribute Details
#default_state_column ⇒ Object
Default column used to store the current state on workflowable models. Overridable per-model via signoff(column: :foo).
27 28 29 |
# File 'lib/signoff/configuration.rb', line 27 def default_state_column @default_state_column end |
#dependent ⇒ Object
:dependent strategy for the events association. Because audit rows are immutable by default, use an SQL-level strategy (:delete_all or :nullify) rather than :destroy, which instantiates and would be blocked by the read-only guard.
41 42 43 |
# File 'lib/signoff/configuration.rb', line 41 def dependent @dependent end |
#event_table_name ⇒ Object
Physical table name backing Signoff::Event.
30 31 32 |
# File 'lib/signoff/configuration.rb', line 30 def event_table_name @event_table_name end |
#immutable_events ⇒ Object
When true (the default) persisted events are read-only: they cannot be updated or destroyed through ActiveRecord, guaranteeing an immutable audit trail. Set to false to allow :destroy as a dependent strategy.
46 47 48 |
# File 'lib/signoff/configuration.rb', line 46 def immutable_events @immutable_events end |
#store_user_agent ⇒ Object
When true, the user_agent captured in Signoff::Current (or passed explicitly) is persisted on every event.
23 24 25 |
# File 'lib/signoff/configuration.rb', line 23 def store_user_agent @store_user_agent end |
#track_ip_addresses ⇒ Object
When true, the ip_address captured in Signoff::Current (or passed explicitly) is persisted on every event.
19 20 21 |
# File 'lib/signoff/configuration.rb', line 19 def track_ip_addresses @track_ip_addresses end |
#user_class ⇒ Object
String name of the model that represents the acting user. Resolved lazily so the constant does not have to be loaded at boot.
15 16 17 |
# File 'lib/signoff/configuration.rb', line 15 def user_class @user_class end |
#validate_on_transition ⇒ Object
When true the workflowable record is fully validated before its state column is written. When false (the default) only the state column is updated, so unrelated validation errors never block a transition.
35 36 37 |
# File 'lib/signoff/configuration.rb', line 35 def validate_on_transition @validate_on_transition end |
Instance Method Details
#user_model ⇒ Object
Resolve the configured user class constant. Returns nil when the constant cannot be loaded (e.g. in a library context with no User model).
61 62 63 64 65 66 67 |
# File 'lib/signoff/configuration.rb', line 61 def user_model return nil if user_class.nil? user_class.to_s.constantize rescue NameError nil end |