rails-workflow 1.4.11 → 1.4.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b8bdc4bd121ea33bf5c173251fbad21009ddeb72
4
- data.tar.gz: f593969d04cbb64b74cb551da7e7b06ca7e3fcd6
3
+ metadata.gz: 7d215275ad6a4ce79e08310152150012a3cc8ac0
4
+ data.tar.gz: 970e42fdc6b4d5f4d2cd78a76bcc365847792d45
5
5
  SHA512:
6
- metadata.gz: a09a67020266baa7489303f5713e0fb346b8d8b6db32257332d4c96ec599cd7314888d4cb854479f76834c7d8f17f2d6e3249f16c262706162f7f44f9f97e98a
7
- data.tar.gz: 4161bb384a19eef51d640ff64e0aefb6c3ff373b92259890b0f47428d81f1a21494c5e39b9a35f2126f2e5dd3df8b6da37347a9bc7e7704079bff86b1a8ff3e6
6
+ metadata.gz: 1955fd9145001d3ea4b2dc8bfa8b34e0fb612db028d0d8e24a0ccf01efb51a8a88cc4dd05787ad716419c5d7ec6e20da335031b59ae5cd892aad55bc312f18df
7
+ data.tar.gz: cf316591ef4198441c6c5b21f5220169d73ceeb68642c5cb8d357427413d8d072d3f5fb136744026177ad26892bc18aabac1de628a3723ebd50863f9cc4aa70a
@@ -63,16 +63,49 @@ module Workflow
63
63
  workflow_spec.states.each { |state| define_scopes(state) }
64
64
  end
65
65
 
66
+ # Find objects that are in a terminal state - no available
67
+ # event transitions
68
+ # @return [ActiveRecord::Relation] ActiveRecord query object meeting the criteria
69
+ def in_terminal_state
70
+ with_state workflow_spec.states.select(&:terminal?)
71
+ end
72
+
73
+ # Find objects that are not in a terminal state
74
+ # @return [ActiveRecord::Relation] ActiveRecord query object meeting the criteria
75
+ def not_in_terminal_state
76
+ with_state(workflow_spec.states.reject(&:terminal?))
77
+ end
78
+
79
+ # Locate objects that are in a state tagged with the given tag(s)
80
+ #
81
+ # @param [Symbol] tags List of tags that apply
82
+ # @return [ActiveRecord::Relation] ActiveRecord query object meeting the criteria
66
83
  def state_tagged_with(*tags)
67
- states = workflow_spec.states.tagged_with(tags)
68
- states.map! { |state| state.name.to_s }
69
- where(workflow_state: states)
84
+ with_state workflow_spec.states.tagged_with(tags)
70
85
  end
71
86
 
87
+ # Locate objects that are not in a state tagged with the given tag(s)
88
+ #
89
+ # @param [Symbol] tags List of tags the objects (and their states) should not have
90
+ # @return [ActiveRecord::Relation] ActiveRecord query object meeting the criteria
72
91
  def state_not_tagged_with(*tags)
73
- states = workflow_spec.states.tagged_with(tags)
74
- states.map! { |state| state.name.to_s }
75
- where.not(workflow_state: states)
92
+ with_state workflow_spec.states.not_tagged_with(tags)
93
+ end
94
+
95
+ # Find objects in the given state(s)
96
+ #
97
+ # @param [Object] states Symbol, String or {Workflow::State} objects
98
+ # @return [ActiveRecord::Relation] ActiveRecord query object meeting the criteria
99
+ def with_state(*states)
100
+ states = [states].flatten
101
+ states.map! do |state|
102
+ if state.is_a?(Workflow::State)
103
+ state.name.to_s
104
+ else
105
+ state.to_s
106
+ end
107
+ end
108
+ where(workflow_state: states)
76
109
  end
77
110
 
78
111
  private
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Workflow
3
- VERSION = '1.4.11'
3
+ VERSION = '1.4.12'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-workflow
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.11
4
+ version: 1.4.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Gannon