Module: Workflow::Adapters::ActiveRecord

Extended by:
ActiveSupport::Concern
Defined in:
lib/workflow/adapters/active_record.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#load_workflow_stateObject



11
12
13
# File 'lib/workflow/adapters/active_record.rb', line 11

def load_workflow_state
  read_attribute(self.class.workflow_column)&.to_sym
end

#persist_workflow_state(new_value) ⇒ Object

On transition the new workflow state is immediately saved in the database, if configured to do so.



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/workflow/adapters/active_record.rb', line 17

def persist_workflow_state(new_value)
  # Rails 3.1 or newer
  if persisted? && Workflow.config.persist_workflow_state_immediately
    attrs = { self.class.workflow_column => new_value }
    if Workflow.config.touch_on_update_column
      attrs[:updated_at] = DateTime.now
    end
    update_columns attrs
    new_value
  else
    self[self.class.workflow_column] = new_value
  end
end