workflow-activerecord 0.0.0
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 +7 -0
- data/LICENSE +21 -0
- data/README.md +24 -0
- data/lib/workflow_activerecord/adapters/active_record.rb +71 -0
- data/lib/workflow_activerecord/version.rb +3 -0
- data/lib/workflow_activerecord.rb +18 -0
- metadata +184 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 4c7d45b00f23164bbcea4d293171548b6c303b15dbf82e8ac1939c5decec3ede
|
|
4
|
+
data.tar.gz: 3b7b29f9508ab3ceed367a1615f358d2ca86d149829e655c6a124dc5a034d623
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 882c6a07b5e38e5a4e21c1099041f4c7bca3ed8638761ce8c4a41e0180cba2c0a60a45a4ee4c8f734344d07b575e579ea43bbf5bcd972e3f5844d267e8fd91da
|
|
7
|
+
data.tar.gz: 0af04eadc947502beba7f98c6e1739d8f1c3548d93f0eda5ab2c74cc029c4f983500f0fac5c0f800042a223cd6857ab28ebda0ba9395ba074092e64a0ab472ff
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016 Vladimir Dobriakov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
[](https://rubygems.org/gems/workflow-activerecord)
|
|
3
|
+
[](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
|
+
[](https://codeclimate.com/github/geekq/workflow-activerecord)
|
|
8
|
+
[](https://codeclimate.com/github/geekq/workflow-activerecord/coverage)
|
|
10
|
+
-->
|
|
11
|
+
|
|
12
|
+
# workflow-activerecord
|
|
13
|
+
|
|
14
|
+
**ActiveRecord/Rails Integration for the Workflow library**
|
|
15
|
+
|
|
16
|
+
To use `workflow` with a Rails 5.0 project you now need to include
|
|
17
|
+
|
|
18
|
+
gem 'workflow-activerecord'
|
|
19
|
+
|
|
20
|
+
This will also automatically include the newest version of the core
|
|
21
|
+
'workflow' gem. But you can also choose a specific version:
|
|
22
|
+
|
|
23
|
+
gem 'workflow', '~> 2.0'
|
|
24
|
+
gem 'workflow-activerecord'
|
|
@@ -0,0 +1,71 @@
|
|
|
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
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
|
|
3
|
+
require 'workflow/specification'
|
|
4
|
+
require 'workflow_activerecord/adapters/active_record'
|
|
5
|
+
|
|
6
|
+
begin
|
|
7
|
+
require 'ruby-graphviz'
|
|
8
|
+
require 'active_support/inflector'
|
|
9
|
+
require 'workflow/draw'
|
|
10
|
+
rescue LoadError => e
|
|
11
|
+
$stderr.puts "Could not load the ruby-graphiz or active_support gems for rendering: #{e.message}"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
module WorkflowActiverecord
|
|
15
|
+
def self.included(klass)
|
|
16
|
+
klass.send :include, Adapter::ActiveRecord
|
|
17
|
+
end
|
|
18
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: workflow-activerecord
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Vladimir Dobriakov
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2019-01-07 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rdoc
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '3.12'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '3.12'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: bundler
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: 1.0.0
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 1.0.0
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: activerecord
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3.0'
|
|
48
|
+
- - "<"
|
|
49
|
+
- !ruby/object:Gem::Version
|
|
50
|
+
version: '6'
|
|
51
|
+
type: :development
|
|
52
|
+
prerelease: false
|
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
54
|
+
requirements:
|
|
55
|
+
- - ">="
|
|
56
|
+
- !ruby/object:Gem::Version
|
|
57
|
+
version: '3.0'
|
|
58
|
+
- - "<"
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '6'
|
|
61
|
+
- !ruby/object:Gem::Dependency
|
|
62
|
+
name: sqlite3
|
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
|
64
|
+
requirements:
|
|
65
|
+
- - ">="
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: '0'
|
|
68
|
+
type: :development
|
|
69
|
+
prerelease: false
|
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - ">="
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '0'
|
|
75
|
+
- !ruby/object:Gem::Dependency
|
|
76
|
+
name: mocha
|
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
|
78
|
+
requirements:
|
|
79
|
+
- - ">="
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '0'
|
|
82
|
+
type: :development
|
|
83
|
+
prerelease: false
|
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - ">="
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '0'
|
|
89
|
+
- !ruby/object:Gem::Dependency
|
|
90
|
+
name: rake
|
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
|
92
|
+
requirements:
|
|
93
|
+
- - ">="
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: '0'
|
|
96
|
+
type: :development
|
|
97
|
+
prerelease: false
|
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
99
|
+
requirements:
|
|
100
|
+
- - ">="
|
|
101
|
+
- !ruby/object:Gem::Version
|
|
102
|
+
version: '0'
|
|
103
|
+
- !ruby/object:Gem::Dependency
|
|
104
|
+
name: test-unit
|
|
105
|
+
requirement: !ruby/object:Gem::Requirement
|
|
106
|
+
requirements:
|
|
107
|
+
- - ">="
|
|
108
|
+
- !ruby/object:Gem::Version
|
|
109
|
+
version: '0'
|
|
110
|
+
type: :development
|
|
111
|
+
prerelease: false
|
|
112
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
113
|
+
requirements:
|
|
114
|
+
- - ">="
|
|
115
|
+
- !ruby/object:Gem::Version
|
|
116
|
+
version: '0'
|
|
117
|
+
- !ruby/object:Gem::Dependency
|
|
118
|
+
name: minitest
|
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
|
120
|
+
requirements:
|
|
121
|
+
- - ">="
|
|
122
|
+
- !ruby/object:Gem::Version
|
|
123
|
+
version: '0'
|
|
124
|
+
type: :development
|
|
125
|
+
prerelease: false
|
|
126
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
127
|
+
requirements:
|
|
128
|
+
- - ">="
|
|
129
|
+
- !ruby/object:Gem::Version
|
|
130
|
+
version: '0'
|
|
131
|
+
- !ruby/object:Gem::Dependency
|
|
132
|
+
name: ruby-graphviz
|
|
133
|
+
requirement: !ruby/object:Gem::Requirement
|
|
134
|
+
requirements:
|
|
135
|
+
- - ">="
|
|
136
|
+
- !ruby/object:Gem::Version
|
|
137
|
+
version: '0'
|
|
138
|
+
type: :development
|
|
139
|
+
prerelease: false
|
|
140
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
141
|
+
requirements:
|
|
142
|
+
- - ">="
|
|
143
|
+
- !ruby/object:Gem::Version
|
|
144
|
+
version: '0'
|
|
145
|
+
description: "ActiveRecord/Rails Integration for the Workflow library. \nWorkflow
|
|
146
|
+
is a finite-state-machine-inspired API for modeling and interacting\n with what
|
|
147
|
+
we tend to refer to as 'workflow'."
|
|
148
|
+
email:
|
|
149
|
+
- vladimir@geekq.net
|
|
150
|
+
executables: []
|
|
151
|
+
extensions: []
|
|
152
|
+
extra_rdoc_files:
|
|
153
|
+
- README.md
|
|
154
|
+
files:
|
|
155
|
+
- LICENSE
|
|
156
|
+
- README.md
|
|
157
|
+
- lib/workflow_activerecord.rb
|
|
158
|
+
- lib/workflow_activerecord/adapters/active_record.rb
|
|
159
|
+
- lib/workflow_activerecord/version.rb
|
|
160
|
+
homepage: http://www.geekq.net/workflow/
|
|
161
|
+
licenses:
|
|
162
|
+
- MIT
|
|
163
|
+
metadata: {}
|
|
164
|
+
post_install_message:
|
|
165
|
+
rdoc_options: []
|
|
166
|
+
require_paths:
|
|
167
|
+
- lib
|
|
168
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
169
|
+
requirements:
|
|
170
|
+
- - ">="
|
|
171
|
+
- !ruby/object:Gem::Version
|
|
172
|
+
version: '2.3'
|
|
173
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
174
|
+
requirements:
|
|
175
|
+
- - ">="
|
|
176
|
+
- !ruby/object:Gem::Version
|
|
177
|
+
version: '0'
|
|
178
|
+
requirements: []
|
|
179
|
+
rubyforge_project:
|
|
180
|
+
rubygems_version: 2.7.6
|
|
181
|
+
signing_key:
|
|
182
|
+
specification_version: 4
|
|
183
|
+
summary: ActiveRecord/Rails Integration for the Workflow library.
|
|
184
|
+
test_files: []
|