Class: Signoff::Configuration

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

Overview

Global, mutable configuration for the gem. Access via Signoff.configuration or set it inside an initializer:

Signoff.configure do |config|
  config.user_class          = "User"
  config.track_ip_addresses  = true
  config.store_user_agent    = true
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

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_columnObject

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

#dependentObject

: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_nameObject

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_eventsObject

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_agentObject

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_addressesObject

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_classObject

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_transitionObject

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_modelObject

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