workflow-activerecord 4.1.3 → 4.1.8

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: b71df1c88832b6becc3a4c594a60a0f42a474200bb74675d3f715c8b042c92a3
4
- data.tar.gz: e192a5ce46f271798c928c3c6202e06516f96a754d960631fc4fff5662d3e03b
3
+ metadata.gz: 5974a889346ecc0b4d47a333a9ce5c2cf9a71073f59dcd2ae7698b38a8e6e1e2
4
+ data.tar.gz: 669f86b67930aa0b140dbf201fb5049d2b3bbe662b4dbb517c50042ae43b8999
5
5
  SHA512:
6
- metadata.gz: 6c1bbe329aa90e5d03c1b82f6664aff19f1dd4e1a44527ff07876155bca04ae8593d5656b99fea77ffd123f157e6de63d880f4bcb5e3d21eb61e411917d2e37a
7
- data.tar.gz: b406b370be0b87830a5e9d5e106f16032e1d03889ec0a3af9b637073768d122a6dbdf77e11b76cb221b74a775f3d3dcd57b0c9a6a726a4976e5d8464ca49e07d
6
+ metadata.gz: 5086caf826c24e788f704738e3bcb297c9edd903638fe4d0bc6a7307bb0ef63731ee5bcad5d6e9a38493c21e988da985fa215b6411a0617efaa61c897c2cff9c
7
+ data.tar.gz: b5b1e5f5f6e446b430fd995fcd5e759e894da22b600af1d0e33e1ae067b8efe803e4120aa46a0dbf8d90d5236634c42b5998d186ea0ab2ef5c4e5a0fdaecab67
data/README.md CHANGED
@@ -1,13 +1,7 @@
1
- [![Version
2
- ](https://img.shields.io/gem/v/workflow-activerecord.svg?maxAge=2592000)](https://rubygems.org/gems/workflow-activerecord)
3
- [![Build Status
4
- ](https://travis-ci.org/geekq/workflow-activerecord.svg)](https://travis-ci.org/geekq/workflow-activerecord)
5
- <!-- TODO find out how to add this repository without giving cloudclimate write access to the repo
6
- [![Code Climate
7
- ](https://codeclimate.com/github/geekq/workflow-activerecord/badges/gpa.svg)](https://codeclimate.com/github/geekq/workflow-activerecord)
8
- [![Test
9
- Coverage](https://codeclimate.com/github/geekq/workflow-activerecord/badges/coverage.svg)](https://codeclimate.com/github/geekq/workflow-activerecord/coverage)
10
- -->
1
+ [![Version](https://img.shields.io/gem/v/workflow-activerecord.svg)](https://rubygems.org/gems/workflow-activerecord)
2
+ [![Build Status](https://travis-ci.org/geekq/workflow-activerecord.svg)](https://travis-ci.org/geekq/workflow-activerecord)
3
+ [![Code Climate](https://codeclimate.com/github/geekq/workflow-activerecord/badges/gpa.svg)](https://codeclimate.com/github/geekq/workflow-activerecord)
4
+ [![Test Coverage](https://codeclimate.com/github/geekq/workflow-activerecord/badges/coverage.svg)](https://codeclimate.com/github/geekq/workflow-activerecord/coverage)
11
5
 
12
6
  # workflow-activerecord
13
7
 
@@ -15,15 +9,15 @@ Coverage](https://codeclimate.com/github/geekq/workflow-activerecord/badges/cove
15
9
 
16
10
  Major+minor versions of workflow-activerecord are based on the oldest
17
11
  compatible ActiveRecord API. To use [`workflow`][workflow] with
18
- Rails/ActiveRecord 4.1, 4.2, 5.0, 5.1, 5.2 please use:
12
+ Rails/ActiveRecord 4.1, 4.2, 5.0, 5.1, 5.2, 6.0, 6.1 please use:
19
13
 
20
- gem 'workflow-activerecord', '>= 4.1', '< 6.0'
14
+ gem 'workflow-activerecord', '~> 4.1'
21
15
 
22
16
  This will also automatically include the newest compatible version of
23
17
  the core 'workflow' gem. But you can also choose a specific version:
24
18
 
25
19
  gem 'workflow', '~> 2.0'
26
- gem 'workflow-activerecord', '>= 4.1pre', '< 6.0'
20
+ gem 'workflow-activerecord', '~> 4.1'
27
21
 
28
22
  Please also have a look at [the sample application][]!
29
23
 
@@ -180,14 +174,38 @@ You can also encapsulate this in a class method or even put in some
180
174
  ActiveRecord callback. Please also have a look at [the full working
181
175
  example][multiple_workflow_test]!
182
176
 
177
+ ### on_transition
178
+
179
+ You can have a look at an advanced [`on_transition`][] example in
180
+ [this test file][advanced_hooks_and_validation_test].
181
+
183
182
  [STI]: http://www.martinfowler.com/eaaCatalog/singleTableInheritance.html
184
183
  [ActiveRecord]: http://api.rubyonrails.org/classes/ActiveRecord/Base.html
185
184
  [multiple_workflow_test]: https://github.com/geekq/workflow-activerecord/blob/develop/test/multiple_workflows_test.rb
186
-
185
+ [`on_transition`]: https://github.com/geekq/workflow#on_transition
186
+ [advanced_hooks_and_validation_test]: http://github.com/geekq/workflow-activerecord/blob/develop/test/advanced_hooks_and_validation_test.rb
187
187
 
188
188
  Changelog
189
189
  ---------
190
190
 
191
+ ### New in the version 4.1.8
192
+
193
+ * gh-11 Rails 6.1 support
194
+
195
+ ### New in the version 4.1.7
196
+
197
+ * gh-9 refactor the implementation to a single file, deprecate `require
198
+ 'workflow_activerecord'` (with the underscore)
199
+
200
+ ### New in the version 4.1.6
201
+
202
+ * gh-3, gh-5 allow automatic require of workflow-activerecord - no need for explicit `require` anymore
203
+
204
+ ### New in the version 4.1.5
205
+
206
+ * gh-2 Show code coverage on codeclimate
207
+ * gh-7 Improve require for base `workflow`
208
+
191
209
  ### New in the version 4.1.3
192
210
 
193
211
  * retire Ruby 2.3 and Rails 4.1 since this Ruby version has reached end of life
@@ -0,0 +1,72 @@
1
+ require 'rubygems'
2
+ require 'workflow'
3
+ require 'workflow/specification'
4
+
5
+ module WorkflowActiverecord
6
+ def self.included(klass)
7
+ klass.send :include, ::Workflow
8
+ klass.send :include, InstanceMethods
9
+ klass.send :extend, Scopes
10
+ klass.before_validation :write_initial_state
11
+ end
12
+
13
+ module InstanceMethods
14
+ def load_workflow_state
15
+ read_attribute(self.class.workflow_column)
16
+ end
17
+
18
+ # On transition the new workflow state is immediately saved in the
19
+ # database.
20
+ def persist_workflow_state(new_value)
21
+ # Rails 3.1 or newer
22
+ update_column self.class.workflow_column, new_value
23
+ end
24
+
25
+ private
26
+
27
+ # Motivation: even if NULL is stored in the workflow_state database column,
28
+ # the current_state is correctly recognized in the Ruby code. The problem
29
+ # arises when you want to SELECT records filtering by the value of initial
30
+ # state. That's why it is important to save the string with the name of the
31
+ # initial state in all the new records.
32
+ def write_initial_state
33
+ write_attribute self.class.workflow_column, current_state.to_s
34
+ end
35
+ end
36
+
37
+ # This module will automatically generate ActiveRecord scopes based on workflow states.
38
+ # The name of each generated scope will be something like `with_<state_name>_state`
39
+ #
40
+ # Examples:
41
+ #
42
+ # Article.with_pending_state # => ActiveRecord::Relation
43
+ # Payment.without_refunded_state # => ActiveRecord::Relation
44
+ #`
45
+ # Example above just adds `where(:state_column_name => 'pending')` or
46
+ # `where.not(:state_column_name => 'pending')` to AR query and returns
47
+ # ActiveRecord::Relation.
48
+ module Scopes
49
+ def self.extended(object)
50
+ class << object
51
+ alias_method :workflow_without_scopes, :workflow unless method_defined?(:workflow_without_scopes)
52
+ alias_method :workflow, :workflow_with_scopes
53
+ end
54
+ end
55
+
56
+ def workflow_with_scopes(&specification)
57
+ workflow_without_scopes(&specification)
58
+ states = workflow_spec.states.values
59
+
60
+ states.each do |state|
61
+ define_singleton_method("with_#{state}_state") do
62
+ where("#{table_name}.#{self.workflow_column.to_sym} = ?", state.to_s)
63
+ end
64
+
65
+ define_singleton_method("without_#{state}_state") do
66
+ where.not("#{table_name}.#{self.workflow_column.to_sym} = ?", state.to_s)
67
+ end
68
+ end
69
+ end
70
+
71
+ end
72
+ end
@@ -1,3 +1,3 @@
1
1
  module WorkflowActiverecord
2
- VERSION = "4.1.3"
2
+ VERSION = "4.1.8"
3
3
  end
@@ -1,11 +1,11 @@
1
- require 'rubygems'
1
+ warn <<HERE
2
2
 
3
- require 'workflow/specification'
4
- require 'workflow_activerecord/adapters/active_record'
3
+ DEPRECATED: `require 'workflow_activerecord'` is obsolete. Usually you can just
4
+ remove the require line. In Rails, adding gem to Gemfile should be enough.
5
+ `bundle.require` will take care. If you need to require explicitely, use
6
+ workflow-activerecord (with dash) instead. The module with underscore will be
7
+ deleted on 4.2 release."
5
8
 
6
- module WorkflowActiverecord
7
- def self.included(klass)
8
- klass.send :include, ::Workflow
9
- klass.send :include, Adapter::ActiveRecord
10
- end
11
- end
9
+ HERE
10
+
11
+ require_relative 'workflow-activerecord'
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.3
4
+ version: 4.1.8
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-04-11 00:00:00.000000000 Z
11
+ date: 2021-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: workflow
@@ -33,7 +33,7 @@ dependencies:
33
33
  version: '3.0'
34
34
  - - "<"
35
35
  - !ruby/object:Gem::Version
36
- version: '6'
36
+ version: '6.2'
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
@@ -43,7 +43,7 @@ dependencies:
43
43
  version: '3.0'
44
44
  - - "<"
45
45
  - !ruby/object:Gem::Version
46
- version: '6'
46
+ version: '6.2'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rdoc
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -128,9 +128,10 @@ dependencies:
128
128
  - - "~>"
129
129
  - !ruby/object:Gem::Version
130
130
  version: '1.3'
131
- description: "ActiveRecord/Rails Integration for the Workflow library. \nWorkflow
132
- is a finite-state-machine-inspired API for modeling and interacting\n with what
133
- we tend to refer to as 'workflow'."
131
+ description: |
132
+ ActiveRecord/Rails Integration for the Workflow library.
133
+ Workflow is a finite-state-machine-inspired API for modeling and interacting
134
+ with what we tend to refer to as 'workflow'.
134
135
  email:
135
136
  - vladimir@geekq.net
136
137
  executables: []
@@ -140,10 +141,10 @@ extra_rdoc_files:
140
141
  files:
141
142
  - LICENSE
142
143
  - README.md
144
+ - lib/workflow-activerecord.rb
145
+ - lib/workflow-activerecord/version.rb
143
146
  - lib/workflow_activerecord.rb
144
- - lib/workflow_activerecord/adapters/active_record.rb
145
- - lib/workflow_activerecord/version.rb
146
- homepage: http://www.geekq.net/workflow/
147
+ homepage: https://github.com/geekq/workflow-activerecord
147
148
  licenses:
148
149
  - MIT
149
150
  metadata: {}
@@ -162,8 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
163
  - !ruby/object:Gem::Version
163
164
  version: '0'
164
165
  requirements: []
165
- rubyforge_project:
166
- rubygems_version: 2.7.6
166
+ rubygems_version: 3.1.2
167
167
  signing_key:
168
168
  specification_version: 4
169
169
  summary: ActiveRecord/Rails Integration for the Workflow library.
@@ -1,71 +0,0 @@
1
- module WorkflowActiverecord
2
- module Adapter
3
- module ActiveRecord
4
- def self.included(klass)
5
- klass.send :include, Adapter::ActiveRecord::InstanceMethods
6
- klass.send :extend, Adapter::ActiveRecord::Scopes
7
- klass.before_validation :write_initial_state
8
- end
9
-
10
- module InstanceMethods
11
- def load_workflow_state
12
- read_attribute(self.class.workflow_column)
13
- end
14
-
15
- # On transition the new workflow state is immediately saved in the
16
- # database.
17
- def persist_workflow_state(new_value)
18
- # Rails 3.1 or newer
19
- update_column self.class.workflow_column, new_value
20
- end
21
-
22
- private
23
-
24
- # Motivation: even if NULL is stored in the workflow_state database column,
25
- # the current_state is correctly recognized in the Ruby code. The problem
26
- # arises when you want to SELECT records filtering by the value of initial
27
- # state. That's why it is important to save the string with the name of the
28
- # initial state in all the new records.
29
- def write_initial_state
30
- write_attribute self.class.workflow_column, current_state.to_s
31
- end
32
- end
33
-
34
- # This module will automatically generate ActiveRecord scopes based on workflow states.
35
- # The name of each generated scope will be something like `with_<state_name>_state`
36
- #
37
- # Examples:
38
- #
39
- # Article.with_pending_state # => ActiveRecord::Relation
40
- # Payment.without_refunded_state # => ActiveRecord::Relation
41
- #`
42
- # Example above just adds `where(:state_column_name => 'pending')` or
43
- # `where.not(:state_column_name => 'pending')` to AR query and returns
44
- # ActiveRecord::Relation.
45
- module Scopes
46
- def self.extended(object)
47
- class << object
48
- alias_method :workflow_without_scopes, :workflow unless method_defined?(:workflow_without_scopes)
49
- alias_method :workflow, :workflow_with_scopes
50
- end
51
- end
52
-
53
- def workflow_with_scopes(&specification)
54
- workflow_without_scopes(&specification)
55
- states = workflow_spec.states.values
56
-
57
- states.each do |state|
58
- define_singleton_method("with_#{state}_state") do
59
- where("#{table_name}.#{self.workflow_column.to_sym} = ?", state.to_s)
60
- end
61
-
62
- define_singleton_method("without_#{state}_state") do
63
- where.not("#{table_name}.#{self.workflow_column.to_sym} = ?", state.to_s)
64
- end
65
- end
66
- end
67
-
68
- end
69
- end
70
- end
71
- end