workflow-activerecord 4.1.6 → 4.1.7

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: bc0778e2f9db691ae5cc166939ac6f989cde65a6c29cc530f4c9347ca0f9e2ec
4
- data.tar.gz: 30346dc259a8159dd8ee5930e4f711683ea7244afa82ab7f094f16f2931a3b1d
3
+ metadata.gz: 410db62b32e62adf3377dcecdbf9d6c42dda109a1fbb63a0cabc379ba8291bc1
4
+ data.tar.gz: ad1b249687e8b7f082a213b19e229eee2bd7e6530e4696aa8f253029d68e273a
5
5
  SHA512:
6
- metadata.gz: ac3d0dd3d4a17491e392ba1deb7935a3dad8130af5ce3814eee6be8c611732c788a957016fe6fe7a60c38e3cc0e0216e026f7cb5c36e5ed54c854ba1b864ab7d
7
- data.tar.gz: 903ed98a7b0a344021a4a71bfb5cb3c5150edb2ae39ea9f991402f822b6a82f554eec44f7eefee96e07697ed9e9568cf7f3bcb33f564674bd14c8d99739e8629
6
+ metadata.gz: 836f6c60d6db535c399567ec63c4193bf5bb57c7e366d64489d4fb3c3d51de369e8803131a7eb78f5ef14b48a996893c200a8e8d0aaf42e781d9eb05b75d4f01
7
+ data.tar.gz: b3680f266639313d3c2ffa8861730cf2f975ee022b1c6a385593270a4029c0eafdf9d689e614620881075f96a5045e6f13b28c0b3abacd978e9c76a009ee3cca
data/README.md CHANGED
@@ -1,7 +1,5 @@
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)
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)
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
 
@@ -190,6 +188,11 @@ 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.7
192
+
193
+ * gh-9 refactor the implementation to a single file, deprecate `require
194
+ 'workflow_activerecord'` (with the underscore)
195
+
193
196
  ### New in the version 4.1.6
194
197
 
195
198
  * gh-3, gh-5 allow automatic require of workflow-activerecord - no need for explicit `require` anymore
@@ -1 +1,72 @@
1
- require_relative 'workflow_activerecord'
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.6"
2
+ VERSION = "4.1.7"
3
3
  end
@@ -1,11 +1,11 @@
1
- require 'rubygems'
2
- require 'workflow'
3
- require 'workflow/specification'
4
- require 'workflow_activerecord/adapters/active_record'
1
+ warn <<HERE
5
2
 
6
- module WorkflowActiverecord
7
- def self.included(klass)
8
- klass.send :include, ::Workflow
9
- klass.send :include, Adapter::ActiveRecord
10
- end
11
- end
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.6
4
+ version: 4.1.7
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-06-03 00:00:00.000000000 Z
11
+ date: 2019-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: workflow
@@ -142,9 +142,8 @@ files:
142
142
  - LICENSE
143
143
  - README.md
144
144
  - lib/workflow-activerecord.rb
145
+ - lib/workflow-activerecord/version.rb
145
146
  - lib/workflow_activerecord.rb
146
- - lib/workflow_activerecord/adapters/active_record.rb
147
- - lib/workflow_activerecord/version.rb
148
147
  homepage: https://github.com/geekq/workflow-activerecord
149
148
  licenses:
150
149
  - MIT
@@ -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