workflow 2.0.0.pre → 2.0.0

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: f86a2a059cb997a5c36395d7f8bab2b572e3468cd7e93819daa37ddb33dd7685
4
- data.tar.gz: af05dfbb7fbcb238641acb8bad34e78c47afbcbb078dbc71fcd217027b487209
3
+ metadata.gz: 60901ed58fefbe1ef7c4e6b4ec5f06c307c3b6c1669f6838d9990bd15ef452ad
4
+ data.tar.gz: d4f5f51c86f382b65ae4850ede4a7749f9dcc2153e544cdf3c068a0af7561799
5
5
  SHA512:
6
- metadata.gz: 79e6e4f70e76e0bce0bfaebfba3e6f20def8b0da4eb9ed6dd8493ae10efe8c5baed5a40ae5d9a7c2c0b1489fdcd2d76445a7f39b8e087998d506635478a9797c
7
- data.tar.gz: ba55dc2332a66ad167e2522b20fff129dc6eff37778a996acb74c44e931864cf2e321079136a1b41bd96ad590b4fb66ae1ef3b9ad08a0ef9c5a52d61924c7607
6
+ metadata.gz: dd5fc9eeb0062c0dd432406be66c47bf64530c5f89b95364af6cc92821199c821e895ad16eab361939f02c6ccbbf21bcba33048e2014f56dd920a7bb22219382
7
+ data.tar.gz: 7d9ca2e0b4e8873bb3802944f29879f0606ccf14adc392cb6a63e5ba2fe2a5c70245fc78e4a4026b374f9b39b4d3330630df2398f22187c86ae2be32da17d78d
@@ -10,17 +10,9 @@ at http://rubygems.org/gems/workflow : select a version (optional,
10
10
  default is latest release), click "Documentation" link. When reading on
11
11
  github.com, the README refers to the upcoming release.
12
12
 
13
- **Note on ActiveRecord/Rails 4.\*, 5.\* Support:**
14
-
15
- Since integration with ActiveRecord makes over 90% of the issues and
16
- maintenance effort, and also to allow for an independent (faster) release cycle
17
- for Rails support, starting with workflow **version 2.0** the support for
18
- ActiveRecord (4.\*, 5.\* and newer) is extracted into a separate
19
- [workflow-activerecord](https://github.com/geekq/workflow-activerecord) gem.
20
-
21
- You can also implement
22
- [your own state persistence](https://github.com/geekq/workflow#custom-workflow-state-persistence)
23
- for ActiveRecord or any other persistence library.
13
+ **Note: Workflow 2.0 is a major refactoring of the library.
14
+ For different options/troubleshooting using it with your Rails application see
15
+ [State persistence with ActiveRecord](#state-persistence-with-activerecord).**
24
16
 
25
17
  What is workflow?
26
18
  -----------------
@@ -91,8 +83,8 @@ of possible events and other meta information:
91
83
  @transitions_to=:awaiting_review, @name=:submit, @meta={}>},
92
84
  name:new, meta{}
93
85
 
94
- On Ruby 1.9 and above, you can check whether a state comes before or
95
- after another state (by the order they were defined):
86
+ You can also check, whether a state comes before or after another state (by the
87
+ order they were defined):
96
88
 
97
89
  article.current_state
98
90
  => being_reviewed
@@ -129,16 +121,6 @@ install the `activesupport` and `ruby-graphviz` gems.
129
121
  Versions up to and including 1.0.0 are also available as a single file download -
130
122
  [lib/workflow.rb file](https://github.com/geekq/workflow/blob/v1.0.0/lib/workflow.rb).
131
123
 
132
- Ruby 1.9
133
- --------
134
-
135
- Workflow gem does not work with some Ruby 1.9
136
- builds due to a known bug in Ruby 1.9. Either
137
-
138
- * use newer ruby build, 1.9.2-p136 and -p180 tested to work
139
- * or compile your Ruby 1.9 from source
140
- * or [comment out some lines in workflow](http://github.com/geekq/workflow/issues#issue/6)
141
- (reduces functionality).
142
124
 
143
125
  Examples
144
126
  --------
@@ -208,73 +190,29 @@ due to a deep nesting. We tried (and dismissed) lambdas for this. Eventually
208
190
  we decided to invoke an optional user defined callback method with the same
209
191
  name as the event (convention over configuration) as explained before.
210
192
 
193
+ State persistence with ActiveRecord
194
+ -----------------------------------
211
195
 
212
- Integration with ActiveRecord
213
- -----------------------------
214
-
215
- Workflow library can handle the state persistence fully automatically. You
216
- only need to define a string field on the table called `workflow_state`
217
- and include the workflow mixin in your model class as usual:
218
-
219
- class Order < ActiveRecord::Base
220
- include Workflow
221
- workflow do
222
- # list states and transitions here
223
- end
224
- end
225
-
226
- On a database record loading all the state check methods e.g.
227
- `article.state`, `article.awaiting_review?` are immediately available.
228
- For new records or if the `workflow_state` field is not set the state
229
- defaults to the first state declared in the workflow specification. In
230
- our example it is `:new`, so `Article.new.new?` returns true and
231
- `Article.new.approved?` returns false.
232
-
233
- At the end of a successful state transition like `article.approve!` the
234
- new state is immediately saved in the database.
235
-
236
- You can change this behaviour by overriding `persist_workflow_state`
237
- method.
238
-
239
- ### Scopes
240
-
241
- Workflow library also adds automatically generated scopes with names based on
242
- states names:
243
-
244
- class Order < ActiveRecord::Base
245
- include Workflow
246
- workflow do
247
- state :approved
248
- state :pending
249
- end
250
- end
251
-
252
- # returns all orders with `approved` state
253
- Order.with_approved_state
254
-
255
- # returns all orders with `pending` state
256
- Order.with_pending_state
257
-
258
-
259
- ### Custom workflow database column
196
+ Note: Workflow 2.0 is a major refactoring for the `worklow` library.
197
+ If your application suddenly breaks after the workflow 2.0 release, you've
198
+ probably got your Gemfile wrong ;-). workflow uses [semantic versioning][]. For
199
+ highest compatibility please reference the desired major+minor version.
260
200
 
261
- [meuble](http://imeuble.info/) contributed a solution for using
262
- custom persistence column easily, e.g. for a legacy database schema:
263
-
264
- class LegacyOrder < ActiveRecord::Base
265
- include Workflow
266
-
267
- workflow_column :foo_bar # use this legacy database column for
268
- # persistence
269
- end
201
+ Note on ActiveRecord/Rails 4.\*, 5.\* Support:
270
202
 
203
+ Since integration with ActiveRecord makes over 90% of the issues and
204
+ maintenance effort, and also to allow for an independent (faster) release cycle
205
+ for Rails support, starting with workflow **version 2.0** in January 2019 the
206
+ support for ActiveRecord (4.\*, 5.\* and newer) has been extracted into a separate
207
+ gem. Read at [workflow-activerecord][], how to include the right gem.
271
208
 
209
+ To use legacy built-in ActiveRecord 2.3 - 4.* support, reference Workflow 1.2 in
210
+ your Gemfile:
272
211
 
273
- ### Single table inheritance
212
+ gem 'workflow', '~> 1.2'
274
213
 
275
- Single table inheritance is also supported. Descendant classes can either
276
- inherit the workflow definition from the parent or override with its own
277
- definition.
214
+ [semantic versioning]: https://guides.rubygems.org/patterns/#semantic-versioning
215
+ [workflow-activerecord]: https://github.com/geekq/workflow-activerecord
278
216
 
279
217
  Custom workflow state persistence
280
218
  ---------------------------------
@@ -385,25 +323,6 @@ also know, if you need any interface beyond `load_workflow_state` and
385
323
  favorite database.
386
324
 
387
325
 
388
- Custom Versions of Existing Adapters
389
- ------------------------------------
390
-
391
- Other adapters (such as a custom ActiveRecord plugin) can be selected by adding a `workflow_adapter` class method, eg.
392
-
393
- ```ruby
394
- class Example < ActiveRecord::Base
395
- def self.workflow_adapter
396
- MyCustomAdapter
397
- end
398
- include Workflow
399
-
400
- # ...
401
- end
402
- ```
403
-
404
- (The above will include `MyCustomAdapter` *instead* of `Workflow::Adapter::ActiveRecord`.)
405
-
406
-
407
326
  Accessing your workflow specification
408
327
  -------------------------------------
409
328
 
@@ -548,69 +467,6 @@ The whole event sequence is as follows:
548
467
  * after_transition
549
468
 
550
469
 
551
- Multiple Workflows
552
- ------------------
553
-
554
- I am frequently asked if it's possible to represent multiple "workflows"
555
- in an ActiveRecord class.
556
-
557
- The solution depends on your business logic and how you want to
558
- structure your implementation.
559
-
560
- ### Use Single Table Inheritance
561
-
562
- One solution can be to do it on the class level and use a class
563
- hierarchy. You can use [single table inheritance][STI] so there is only
564
- single `orders` table in the database. Read more in the chapter "Single
565
- Table Inheritance" of the [ActiveRecord documentation][ActiveRecord].
566
- Then you define your different classes:
567
-
568
- class Order < ActiveRecord::Base
569
- include Workflow
570
- end
571
-
572
- class SmallOrder < Order
573
- workflow do
574
- # workflow definition for small orders goes here
575
- end
576
- end
577
-
578
- class BigOrder < Order
579
- workflow do
580
- # workflow for big orders, probably with a longer approval chain
581
- end
582
- end
583
-
584
-
585
- ### Individual workflows for objects
586
-
587
- Another solution would be to connect different workflows to object
588
- instances via metaclass, e.g.
589
-
590
- # Load an object from the database
591
- booking = Booking.find(1234)
592
-
593
- # Now define a workflow - exclusively for this object,
594
- # probably depending on some condition or database field
595
- if # some condition
596
- class << booking
597
- include Workflow
598
- workflow do
599
- state :state1
600
- state :state2
601
- end
602
- end
603
- # if some other condition, use a different workflow
604
-
605
- You can also encapsulate this in a class method or even put in some
606
- ActiveRecord callback. Please also have a look at [the full working
607
- example][multiple_workflow_test]!
608
-
609
- [STI]: http://www.martinfowler.com/eaaCatalog/singleTableInheritance.html
610
- [ActiveRecord]: http://api.rubyonrails.org/classes/ActiveRecord/Base.html
611
- [multiple_workflow_test]: http://github.com/geekq/workflow/blob/master/test/multiple_workflows_test.rb
612
-
613
-
614
470
  Documenting with diagrams
615
471
  -------------------------
616
472
 
@@ -639,49 +495,20 @@ Development Setup
639
495
  bundle exec rake test
640
496
 
641
497
 
642
- Earlier versions
643
- ----------------
644
-
645
- The `workflow` library was originally written by Ryan Allen.
646
-
647
- The version 0.3 was almost completely (including ActiveRecord
648
- integration, API for accessing workflow specification,
649
- method_missing free implementation) rewritten by Vladimir Dobriakov
650
- keeping the original workflow DSL spirit.
651
-
652
-
653
- Migration from the original Ryan's library
654
- ------------------------------------------
655
-
656
- Credit: Michael (rockrep)
657
-
658
- Accessing workflow specification
659
-
660
- my_instance.workflow # old
661
- MyClass.workflow_spec # new
662
-
663
- Accessing states, events, meta, e.g.
664
-
665
- my_instance.workflow.states(:some_state).events(:some_event).meta[:some_meta_tag] # old
666
- MyClass.workflow_spec.states[:some_state].events[:some_event].meta[:some_meta_tag] # new
667
-
668
- Causing state transitions
669
-
670
- my_instance.workflow.my_event # old
671
- my_instance.my_event! # new
672
-
673
- when using both a block and a callback method for an event, the block executes prior to the callback
674
-
675
-
676
498
  Changelog
677
499
  ---------
678
500
 
679
- ### New in the upcoming version 2.0.0
501
+ ### New in the version 2.0.0
680
502
 
681
503
  * extract Rails/ActiveRecord integration into a separate gem
682
504
  workflow-activerecord
683
505
  * Remodel integration removed - needs to be a separate gem
684
506
 
507
+ Special thanks to [voltechs][] for implementing Rails 5 support
508
+ and helping to revive `workflow`!
509
+
510
+ [voltechs]: https://github.com/voltechs
511
+
685
512
  ### New in the upcoming version 1.3.0 (never released)
686
513
 
687
514
  * Retiring Ruby 1.8.7 and Rails 2 support #118. If you still need this older
@@ -814,9 +641,9 @@ Support
814
641
  About
815
642
  -----
816
643
 
817
- Author: Vladimir Dobriakov, <http://www.mobile-web-consulting.de>, <http://blog.geekq.net/>
644
+ Author: Vladimir Dobriakov, <https://infrastructure-as-code.de>
818
645
 
819
- Copyright (c) 2010-2014 Vladimir Dobriakov, www.mobile-web-consulting.de
646
+ Copyright (c) 2010-2019 Vladimir Dobriakov and Contributors
820
647
 
821
648
  Copyright (c) 2008-2009 Vodafone
822
649
 
@@ -15,6 +15,9 @@ module Workflow
15
15
  module ClassMethods
16
16
  attr_reader :workflow_spec
17
17
 
18
+ # Workflow does not provide any state persistence - it is the job of particular
19
+ # persistence libraries for workflow and activerecord or remodel.
20
+ # But it still makes sense to provide a default name and override feature.
18
21
  def workflow_column(column_name=nil)
19
22
  if column_name
20
23
  @workflow_state_column_name = column_name.to_sym
@@ -1,3 +1,3 @@
1
1
  module Workflow
2
- VERSION = "2.0.0.pre"
2
+ VERSION = "2.0.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: workflow
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.pre
4
+ version: 2.0.0
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-08 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: rdoc
@@ -135,9 +135,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
135
135
  version: '2.3'
136
136
  required_rubygems_version: !ruby/object:Gem::Requirement
137
137
  requirements:
138
- - - ">"
138
+ - - ">="
139
139
  - !ruby/object:Gem::Version
140
- version: 1.3.1
140
+ version: '0'
141
141
  requirements: []
142
142
  rubyforge_project:
143
143
  rubygems_version: 2.7.6