Module: Workflow::Adapters::ActiveRecord::ClassMethods
- Defined in:
- lib/workflow/adapters/active_record.rb
Overview
This module will automatically generate ActiveRecord scopes based on workflow states.
The name of each generated scope will be something like with_<state_name>_state
Examples:
Article.with_pending_state # => ActiveRecord::Relation
Payment.without_refunded_state # => ActiveRecord::Relation
Example above just addswhere(:state_column_name => 'pending')or
where.not(:state_column_name => 'pending')` to AR query and returns
ActiveRecord::Relation.
Instance Method Summary collapse
- #workflow(&specification) ⇒ Object
-
#workflow_column(column_name = nil) ⇒ Symbol
Instructs Workflow which column to use to persist workflow state.
Instance Method Details
#workflow(&specification) ⇒ Object
61 62 63 64 |
# File 'lib/workflow/adapters/active_record.rb', line 61 def workflow(&specification) super workflow_spec.states.each { |state| define_scopes(state) } end |
#workflow_column(column_name = nil) ⇒ Symbol
Instructs Workflow which column to use to persist workflow state.
56 57 58 59 |
# File 'lib/workflow/adapters/active_record.rb', line 56 def workflow_column(column_name = nil) @workflow_column = column_name.to_sym if column_name @workflow_column ||= superclass_workflow || :workflow_state end |