workflow-activerecord 4.1.5 → 4.1.9
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc4264f2db70995956591e3b1f241332df5e7f0717d7829a091138c149269755
|
4
|
+
data.tar.gz: f6847f4bb4039ce931fdd38efccb4b18241af15a8c45ffdbff377edb781d6fb1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b0a7089c9de2dcaf624d914c6e37748e11bb0367f0398d3173d557420c3e329493e61f28c65332230c5fd5ebb0433079aedb51507ac4e2cc827215ab35e25513
|
7
|
+
data.tar.gz: 80c0c8fa5b22d407c45837ad603fb9d7adde4ae70070fee745367636502615f5b15e026c7ddd7bab3239b6d9fb6a02cbf1d485ba3beb5a5f74e1dd4b2a2950f4
|
data/README.md
CHANGED
@@ -1,7 +1,5 @@
|
|
1
|
-
[![Version
|
2
|
-
](https://
|
3
|
-
[![Build Status
|
4
|
-
](https://travis-ci.org/geekq/workflow-activerecord.svg)](https://travis-ci.org/geekq/workflow-activerecord)
|
1
|
+
[![Version](https://img.shields.io/gem/v/workflow-activerecord.svg)](https://rubygems.org/gems/workflow-activerecord)
|
2
|
+
[![Test](https://github.com/geekq/workflow-activerecord/actions/workflows/test.yml/badge.svg)](https://github.com/geekq/workflow-activerecord/actions/workflows/test.yml)
|
5
3
|
[![Code Climate](https://codeclimate.com/github/geekq/workflow-activerecord/badges/gpa.svg)](https://codeclimate.com/github/geekq/workflow-activerecord)
|
6
4
|
[![Test Coverage](https://codeclimate.com/github/geekq/workflow-activerecord/badges/coverage.svg)](https://codeclimate.com/github/geekq/workflow-activerecord/coverage)
|
7
5
|
|
@@ -11,15 +9,15 @@
|
|
11
9
|
|
12
10
|
Major+minor versions of workflow-activerecord are based on the oldest
|
13
11
|
compatible ActiveRecord API. To use [`workflow`][workflow] with
|
14
|
-
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:
|
15
13
|
|
16
|
-
gem 'workflow-activerecord', '
|
14
|
+
gem 'workflow-activerecord', '~> 4.1'
|
17
15
|
|
18
16
|
This will also automatically include the newest compatible version of
|
19
17
|
the core 'workflow' gem. But you can also choose a specific version:
|
20
18
|
|
21
19
|
gem 'workflow', '~> 2.0'
|
22
|
-
gem 'workflow-activerecord', '
|
20
|
+
gem 'workflow-activerecord', '~> 4.1'
|
23
21
|
|
24
22
|
Please also have a look at [the sample application][]!
|
25
23
|
|
@@ -190,6 +188,24 @@ You can have a look at an advanced [`on_transition`][] example in
|
|
190
188
|
Changelog
|
191
189
|
---------
|
192
190
|
|
191
|
+
### New in the version 4.1.9
|
192
|
+
|
193
|
+
* gh-13 Switch CI (continuous integration) from travis-CI to GitHub
|
194
|
+
* Tested Rails 7.0 support
|
195
|
+
|
196
|
+
### New in the version 4.1.8
|
197
|
+
|
198
|
+
* gh-11 Rails 6.1 support
|
199
|
+
|
200
|
+
### New in the version 4.1.7
|
201
|
+
|
202
|
+
* gh-9 refactor the implementation to a single file, deprecate `require
|
203
|
+
'workflow_activerecord'` (with the underscore)
|
204
|
+
|
205
|
+
### New in the version 4.1.6
|
206
|
+
|
207
|
+
* gh-3, gh-5 allow automatic require of workflow-activerecord - no need for explicit `require` anymore
|
208
|
+
|
193
209
|
### New in the version 4.1.5
|
194
210
|
|
195
211
|
* gh-2 Show code coverage on codeclimate
|
@@ -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,11 +1,11 @@
|
|
1
|
-
|
2
|
-
require 'workflow'
|
3
|
-
require 'workflow/specification'
|
4
|
-
require 'workflow_activerecord/adapters/active_record'
|
1
|
+
warn <<HERE
|
5
2
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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."
|
8
|
+
|
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.
|
4
|
+
version: 4.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Dobriakov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: workflow
|
@@ -31,9 +31,6 @@ dependencies:
|
|
31
31
|
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '3.0'
|
34
|
-
- - "<"
|
35
|
-
- !ruby/object:Gem::Version
|
36
|
-
version: '6.1'
|
37
34
|
type: :runtime
|
38
35
|
prerelease: false
|
39
36
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -41,9 +38,6 @@ dependencies:
|
|
41
38
|
- - ">="
|
42
39
|
- !ruby/object:Gem::Version
|
43
40
|
version: '3.0'
|
44
|
-
- - "<"
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: '6.1'
|
47
41
|
- !ruby/object:Gem::Dependency
|
48
42
|
name: rdoc
|
49
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -141,9 +135,9 @@ extra_rdoc_files:
|
|
141
135
|
files:
|
142
136
|
- LICENSE
|
143
137
|
- README.md
|
138
|
+
- lib/workflow-activerecord.rb
|
139
|
+
- lib/workflow-activerecord/version.rb
|
144
140
|
- lib/workflow_activerecord.rb
|
145
|
-
- lib/workflow_activerecord/adapters/active_record.rb
|
146
|
-
- lib/workflow_activerecord/version.rb
|
147
141
|
homepage: https://github.com/geekq/workflow-activerecord
|
148
142
|
licenses:
|
149
143
|
- MIT
|
@@ -163,8 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
157
|
- !ruby/object:Gem::Version
|
164
158
|
version: '0'
|
165
159
|
requirements: []
|
166
|
-
|
167
|
-
rubygems_version: 2.7.6
|
160
|
+
rubygems_version: 3.1.2
|
168
161
|
signing_key:
|
169
162
|
specification_version: 4
|
170
163
|
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
|