workflow-activerecord 4.1.1.pre → 4.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ae6e5038a156d5f4e9e6e3fee2b230bc857b683ac75bb17a2c5d1910069e01b7
4
- data.tar.gz: 6cb41ab01b13c94e84b57fa1a7daa0333053a48f813d8bcb3e0fa7b8d9b63346
3
+ metadata.gz: 6e4b0f04924472fad5ba5fe6b917c13bdc9b023ee21b5fc57a4362ee659cda3b
4
+ data.tar.gz: 9949cfc0c4677cdd75f821a8fc1fa86f781d30165fe2e492cd93d4115b9a39dc
5
5
  SHA512:
6
- metadata.gz: 81fa68fcd2224a357bf70a10c263c9b59b4edb65abc181b86960d65f8cff479109dfebe6c6d2827caeb626b4840c7a131cfe402a403ebc6a544556515c6f8aaa
7
- data.tar.gz: 43538661e4db5a82e01ae88a60c0b01753455e19b22c012e53f77568359a3c66ac192e4399394008478aa463fe700f07e7e6cb3c7a9212eb5d89923b0b059c45
6
+ metadata.gz: e2c87a9a399dd3c91f966cb2f87ea660400b3376053a9ca3a489189ea433f7962015f52aa4072bc956c5d9a56b6e5d324da6df3a7012c8181f20c659f26028a6
7
+ data.tar.gz: 31498bb866bcfded36c4eda93df32ece31c6fd0f53f71ba83a528e886f199290f8a3b7522814d63b219d1dc219925b5cfc77dc5894a2890faa9570cb7ce55081
data/README.md CHANGED
@@ -13,12 +13,207 @@ Coverage](https://codeclimate.com/github/geekq/workflow-activerecord/badges/cove
13
13
 
14
14
  **ActiveRecord/Rails Integration for the Workflow library**
15
15
 
16
- To use `workflow` with a Rails 5.0 project you now need to include
16
+ Major+minor versions of workflow-activerecord are based on the oldest
17
+ compatible ActiveRecord API. To use [`workflow`][] with a
18
+ Rails/ActiveRecord 4.1, 4.2, 5.0, 5.1, 5.2 please use:
17
19
 
18
- gem 'workflow-activerecord'
20
+ gem 'workflow-activerecord', '>= 4.1', '< 6.0'
19
21
 
20
- This will also automatically include the newest version of the core
21
- 'workflow' gem. But you can also choose a specific version:
22
+ This will also automatically include the newest compatible version of
23
+ the core 'workflow' gem. But you can also choose a specific version:
22
24
 
23
25
  gem 'workflow', '~> 2.0'
24
- gem 'workflow-activerecord'
26
+ gem 'workflow-activerecord', '>= 4.1pre', '< 6.0'
27
+
28
+ Please also have a look at the [sample application][]!
29
+
30
+ For detailed introduction into workflow DSL please read [`workflow`][]!
31
+
32
+ [`workflow`]: https://github.com/geekq/workflow
33
+ [sample application]: https://github.com/geekq/workflow-rails-sample
34
+
35
+
36
+ State persistence with ActiveRecord
37
+ -----------------------------------
38
+
39
+ Workflow library can handle the state persistence fully automatically. You
40
+ only need to define a string field on the table called `workflow_state`
41
+ and include the workflow mixin in your model class as usual:
42
+
43
+ class Order < ApplicationRecord
44
+ include Workflow
45
+ workflow do
46
+ # list states and transitions here
47
+ end
48
+ end
49
+
50
+ On a database record loading all the state check methods e.g.
51
+ `article.state`, `article.awaiting_review?` are immediately available.
52
+ For new records or if the `workflow_state` field is not set the state
53
+ defaults to the first state declared in the workflow specification. In
54
+ our example it is `:new`, so `Article.new.new?` returns true and
55
+ `Article.new.approved?` returns false.
56
+
57
+ At the end of a successful state transition like `article.approve!` the
58
+ new state is immediately saved in the database.
59
+
60
+ You can change this behaviour by overriding `persist_workflow_state`
61
+ method.
62
+
63
+ ### Scopes
64
+
65
+ Workflow library also adds automatically generated scopes with names based on
66
+ states names:
67
+
68
+ class Order < ApplicationRecord
69
+ include Workflow
70
+ workflow do
71
+ state :approved
72
+ state :pending
73
+ end
74
+ end
75
+
76
+ # returns all orders with `approved` state
77
+ Order.with_approved_state
78
+
79
+ # returns all orders with `pending` state
80
+ Order.with_pending_state
81
+
82
+
83
+ ### Custom workflow database column
84
+
85
+ [meuble](http://imeuble.info/) contributed a solution for using
86
+ custom persistence column easily, e.g. for a legacy database schema:
87
+
88
+ class LegacyOrder < ApplicationRecord
89
+ include Workflow
90
+
91
+ workflow_column :foo_bar # use this legacy database column for
92
+ # persistence
93
+ end
94
+
95
+
96
+
97
+ ### Single table inheritance
98
+
99
+ Single table inheritance is also supported. Descendant classes can either
100
+ inherit the workflow definition from the parent or override with its own
101
+ definition.
102
+
103
+
104
+ Custom Versions of Existing Adapters
105
+ ------------------------------------
106
+
107
+ Other adapters (such as a custom ActiveRecord plugin) can be selected by adding a `workflow_adapter` class method, eg.
108
+
109
+ ```ruby
110
+ class Example < ApplicationRecord
111
+ def self.workflow_adapter
112
+ MyCustomAdapter
113
+ end
114
+ include Workflow
115
+
116
+ # ...
117
+ end
118
+ ```
119
+
120
+ (The above will include `MyCustomAdapter` *instead* of the default
121
+ `WorkflowActiverecord` adapter.)
122
+
123
+
124
+ Multiple Workflows
125
+ ------------------
126
+
127
+ I am frequently asked if it's possible to represent multiple "workflows"
128
+ in an ActiveRecord class.
129
+
130
+ The solution depends on your business logic and how you want to
131
+ structure your implementation.
132
+
133
+ ### Use Single Table Inheritance
134
+
135
+ One solution can be to do it on the class level and use a class
136
+ hierarchy. You can use [single table inheritance][STI] so there is only
137
+ single `orders` table in the database. Read more in the chapter "Single
138
+ Table Inheritance" of the [ActiveRecord documentation][ActiveRecord].
139
+ Then you define your different classes:
140
+
141
+ class Order < ActiveRecord::Base
142
+ include Workflow
143
+ end
144
+
145
+ class SmallOrder < Order
146
+ workflow do
147
+ # workflow definition for small orders goes here
148
+ end
149
+ end
150
+
151
+ class BigOrder < Order
152
+ workflow do
153
+ # workflow for big orders, probably with a longer approval chain
154
+ end
155
+ end
156
+
157
+
158
+ ### Individual workflows for objects
159
+
160
+ Another solution would be to connect different workflows to object
161
+ instances via metaclass, e.g.
162
+
163
+ # Load an object from the database
164
+ booking = Booking.find(1234)
165
+
166
+ # Now define a workflow - exclusively for this object,
167
+ # probably depending on some condition or database field
168
+ if # some condition
169
+ class << booking
170
+ include Workflow
171
+ workflow do
172
+ state :state1
173
+ state :state2
174
+ end
175
+ end
176
+ # if some other condition, use a different workflow
177
+
178
+ You can also encapsulate this in a class method or even put in some
179
+ ActiveRecord callback. Please also have a look at [the full working
180
+ example][multiple_workflow_test]!
181
+
182
+ [STI]: http://www.martinfowler.com/eaaCatalog/singleTableInheritance.html
183
+ [ActiveRecord]: http://api.rubyonrails.org/classes/ActiveRecord/Base.html
184
+ [multiple_workflow_test]: https://github.com/geekq/workflow-activerecord/blob/develop/test/multiple_workflows_test.rb
185
+
186
+
187
+ Changelog
188
+ ---------
189
+
190
+ ### New in the version 4.1.0
191
+
192
+ First version supporting Rails/ActiveRecord 4.1, 4.2, 5.0, 5.1, 5.2
193
+ Special thanks to [@voltechs][] for implementing Rails 5 support
194
+ and helping to revive `workflow`!
195
+
196
+ [@voltechs]: https://github.com/voltechs
197
+
198
+ Support
199
+ -------
200
+
201
+ ### Reporting bugs
202
+
203
+ <http://github.com/geekq/workflow-activerecord/issues>
204
+
205
+
206
+ About
207
+ -----
208
+
209
+ Author: Vladimir Dobriakov, <https://infrastructure-as-code.de>
210
+
211
+ Copyright (c) 2010-2019 Vladimir Dobriakov and Contributors
212
+
213
+ Copyright (c) 2008-2009 Vodafone
214
+
215
+ Copyright (c) 2007-2008 Ryan Allen, FlashDen Pty Ltd
216
+
217
+ Based on the work of Ryan Allen and Scott Barron
218
+
219
+ Licensed under MIT license, see the LICENSE file.
@@ -1,3 +1,3 @@
1
1
  module WorkflowActiverecord
2
- VERSION = "4.1.1.pre"
2
+ VERSION = "4.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: workflow-activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.1.pre
4
+ version: 4.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladimir Dobriakov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-10 00:00:00.000000000 Z
11
+ date: 2019-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: workflow
@@ -186,9 +186,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
186
186
  version: '2.3'
187
187
  required_rubygems_version: !ruby/object:Gem::Requirement
188
188
  requirements:
189
- - - ">"
189
+ - - ">="
190
190
  - !ruby/object:Gem::Version
191
- version: 1.3.1
191
+ version: '0'
192
192
  requirements: []
193
193
  rubyforge_project:
194
194
  rubygems_version: 2.7.6