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
- #state_not_tagged_with(*tags) ⇒ Object
- #state_tagged_with(*tags) ⇒ Object
- #workflow(&specification) ⇒ Object
-
#workflow_column(column_name = nil) ⇒ Symbol
Instructs Workflow which column to use to persist workflow state.
Instance Method Details
#state_not_tagged_with(*tags) ⇒ Object
72 73 74 75 76 |
# File 'lib/workflow/adapters/active_record.rb', line 72 def state_not_tagged_with(*) states = workflow_spec.states.tagged_with() states.map! { |state| state.name.to_s } where.not(workflow_state: states) end |
#state_tagged_with(*tags) ⇒ Object
66 67 68 69 70 |
# File 'lib/workflow/adapters/active_record.rb', line 66 def state_tagged_with(*) states = workflow_spec.states.tagged_with() states.map! { |state| state.name.to_s } where(workflow_state: states) end |
#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 |