acts_as_living 0.1.4 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +4 -0
- data/lib/acts_as_living/acts_as_living.rb +3 -4
- data/lib/acts_as_living/callbacks_definer.rb +22 -22
- data/lib/acts_as_living/enum_definer.rb +1 -1
- data/lib/acts_as_living/methods_definer.rb +26 -26
- data/lib/acts_as_living/scopes_definer.rb +7 -12
- data/lib/acts_as_living/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6623143eb72b9906a984375aa0a2e67d30ae49fd10c17e54d89569b52333ea0e
|
4
|
+
data.tar.gz: 2778b40bf555acea1efce2ed87c199c882a9222ccdce8cde905735903125243d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3327015d9f2002c6d24e641d872d93098a53abf251ced9e2f51a1156e9524efa1f628896fd7ac4c61061e1f9cb53856628402cae7d22f0b62136becd6f4dde45
|
7
|
+
data.tar.gz: 007a78047238697bfaeb646bc4ec7b9dfd2c41861429f4b101acb4d544624851d99e99798aa52b3897ed2443c7f49bb3e5f2010b375c442c6e2f5643a648a838
|
data/Changelog.md
CHANGED
@@ -5,20 +5,19 @@ module ActsAsLiving::ActsAsLiving
|
|
5
5
|
extend ActiveSupport::Concern
|
6
6
|
|
7
7
|
class_methods do
|
8
|
-
def acts_as_living(keys,
|
8
|
+
def acts_as_living(keys, phases: [], lock_on: [], death: :cancelled, spread: 1)
|
9
9
|
@stage_keys = keys
|
10
|
-
@
|
10
|
+
@phases = phases
|
11
11
|
@locked_stages = lock_on
|
12
12
|
@death = death
|
13
13
|
@spread = spread
|
14
|
-
@column = column
|
15
14
|
|
16
15
|
run_definers
|
17
16
|
end
|
18
17
|
|
19
18
|
def run_definers
|
20
|
-
ActsAsLiving::MethodsDefiner.call(self)
|
21
19
|
ActsAsLiving::EnumDefiner.call(self)
|
20
|
+
ActsAsLiving::MethodsDefiner.call(self)
|
22
21
|
ActsAsLiving::ScopesDefiner.call(self)
|
23
22
|
ActsAsLiving::ValidationsDefiner.call(self)
|
24
23
|
end
|
@@ -7,7 +7,7 @@
|
|
7
7
|
# ->(_target, result) { result == false }
|
8
8
|
# end
|
9
9
|
|
10
|
-
# # defines before, after and around callbaks for each
|
10
|
+
# # defines before, after and around callbaks for each phase of the acts_as_living
|
11
11
|
# # e.g. before_cancelled { do_something }
|
12
12
|
# # e.g. after_activated :run_method
|
13
13
|
# # e.g. after_stage_change :run_method
|
@@ -19,9 +19,9 @@
|
|
19
19
|
# include InstanceMethods
|
20
20
|
|
21
21
|
# callbacks_for(:stage_change)
|
22
|
-
# callbacks_for(:
|
22
|
+
# callbacks_for(:phase_change)
|
23
23
|
# stage_keys.each(&method(:stage_callbacks_for))
|
24
|
-
# @
|
24
|
+
# @phases.keys.each(&method(:lifephase_callbacks_for))
|
25
25
|
# end
|
26
26
|
# end
|
27
27
|
|
@@ -32,7 +32,7 @@
|
|
32
32
|
# _run_stage_change_callbacks do
|
33
33
|
# run_callbacks("stage_change_to_#{stage}") do
|
34
34
|
# binding.pry if notice_of_termination_received?
|
35
|
-
#
|
35
|
+
# phase_changed? ? run_phase_callbacks { binding.pry; 'hey'; super(*args) } : super(*args)
|
36
36
|
# end
|
37
37
|
# end
|
38
38
|
# end
|
@@ -42,46 +42,46 @@
|
|
42
42
|
|
43
43
|
# _run_stage_change_callbacks do
|
44
44
|
# run_callbacks("stage_change_to_#{stage}") do
|
45
|
-
#
|
45
|
+
# phase_changed? ? run_phase_callbacks { binding.pry; 'hey'; super(*args) } : super(*args)
|
46
46
|
# end
|
47
47
|
# end
|
48
48
|
# end
|
49
49
|
|
50
50
|
# protected
|
51
51
|
|
52
|
-
# def
|
53
|
-
#
|
54
|
-
#
|
55
|
-
#
|
52
|
+
# def run_phase_callbacks(&block)
|
53
|
+
# _run_phase_change_callbacks do
|
54
|
+
# _run_phase_started_callbacks do
|
55
|
+
# _run_phase_ended_callbacks(&block)
|
56
56
|
# end
|
57
57
|
# end
|
58
58
|
# end
|
59
59
|
|
60
|
-
# def
|
61
|
-
#
|
62
|
-
#
|
60
|
+
# def _run_phase_started_callbacks(&block)
|
61
|
+
# phases_started.inject(block) do |blk, phase|
|
62
|
+
# _run_phase_started_callbacks(phase, &blk)
|
63
63
|
# end
|
64
64
|
# end
|
65
65
|
|
66
|
-
# def
|
67
|
-
#
|
68
|
-
#
|
66
|
+
# def _run_phase_ended_callbacks(&block)
|
67
|
+
# phases_ended.inject(block) do |blk, phase|
|
68
|
+
# _run_phase_ended_callbacks(phase, &blk)
|
69
69
|
# end
|
70
70
|
# end
|
71
71
|
|
72
|
-
# def
|
73
|
-
# run_callbacks("#{
|
72
|
+
# def _run_phase_started_callbacks(phase, &block)
|
73
|
+
# run_callbacks("#{phase}_started".to_sym, &block)
|
74
74
|
# end
|
75
75
|
|
76
|
-
# def
|
77
|
-
# run_callbacks("#{
|
76
|
+
# def _run_phase_ended_callbacks(phase, &block)
|
77
|
+
# run_callbacks("#{phase}_ended".to_sym, &block)
|
78
78
|
# end
|
79
79
|
# end
|
80
80
|
|
81
81
|
# module ClassMethods
|
82
|
-
# def
|
83
|
-
# define_callback_methods_for("#{
|
84
|
-
# define_callback_methods_for("#{
|
82
|
+
# def lifephase_callbacks_for(phase)
|
83
|
+
# define_callback_methods_for("#{phase}_started".to_sym)
|
84
|
+
# define_callback_methods_for("#{phase}_ended".to_sym)
|
85
85
|
# end
|
86
86
|
|
87
87
|
# def callbacks_for(callback_name)
|
@@ -7,7 +7,7 @@ module ActsAsLiving::MethodsDefiner
|
|
7
7
|
include InstanceMethods
|
8
8
|
|
9
9
|
@stage_keys.each(&method(:define_stage_queries))
|
10
|
-
@
|
10
|
+
@phases.each(&method(:define_phase_queries))
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
@@ -64,12 +64,12 @@ module ActsAsLiving::MethodsDefiner
|
|
64
64
|
dead? || dying?
|
65
65
|
end
|
66
66
|
|
67
|
-
def
|
68
|
-
self.class.
|
67
|
+
def klass_phases_with_ranges
|
68
|
+
self.class.phases_with_ranges
|
69
69
|
end
|
70
70
|
|
71
|
-
def
|
72
|
-
self.class.
|
71
|
+
def klass_phases_for(stage)
|
72
|
+
self.class.phases_for(stage)
|
73
73
|
end
|
74
74
|
|
75
75
|
def klass_stages
|
@@ -82,20 +82,20 @@ module ActsAsLiving::MethodsDefiner
|
|
82
82
|
@locked_on.to_set.intersect? [stage, stage_was].to_set
|
83
83
|
end
|
84
84
|
|
85
|
-
def
|
86
|
-
|
85
|
+
def phases
|
86
|
+
klass_phases_for(stage)
|
87
87
|
end
|
88
88
|
|
89
|
-
def
|
90
|
-
|
89
|
+
def phase_changed?
|
90
|
+
klass_phases_for(stage) != klass_phases_for(stage_was)
|
91
91
|
end
|
92
92
|
|
93
|
-
def
|
94
|
-
|
93
|
+
def phases_started
|
94
|
+
klass_phases_for(stage) - klass_phases_for(stage_was)
|
95
95
|
end
|
96
96
|
|
97
|
-
def
|
98
|
-
|
97
|
+
def phases_ended
|
98
|
+
klass_phases_for(stage_was) - klass_phases_for(stage)
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
@@ -155,26 +155,26 @@ module ActsAsLiving::MethodsDefiner
|
|
155
155
|
initial_stage == stage
|
156
156
|
end
|
157
157
|
|
158
|
-
def
|
159
|
-
@
|
158
|
+
def phases_with_ranges
|
159
|
+
@phases.map(&method(:to_phase_with_range)).to_h
|
160
160
|
end
|
161
161
|
|
162
|
-
def
|
163
|
-
[
|
162
|
+
def to_phase_with_range(phase, delimiter)
|
163
|
+
[phase, (stages[delimiter.first]..stages[delimiter.last])]
|
164
164
|
end
|
165
165
|
|
166
|
-
def
|
167
|
-
@
|
166
|
+
def phases
|
167
|
+
@phases
|
168
168
|
end
|
169
169
|
|
170
|
-
def
|
171
|
-
|
172
|
-
|
170
|
+
def phases_for(stage)
|
171
|
+
phases_with_ranges.keys.select do |phase|
|
172
|
+
phases_with_ranges[phase].include? stages[stage]
|
173
173
|
end
|
174
174
|
end
|
175
175
|
|
176
|
-
def
|
177
|
-
define_method("#{
|
176
|
+
def define_phase_queries(phase, delimiters)
|
177
|
+
define_method("#{phase}?") do
|
178
178
|
if delimiters.length == 1
|
179
179
|
klass_stages[stage] == klass_stages[delimiters]
|
180
180
|
else
|
@@ -183,11 +183,11 @@ module ActsAsLiving::MethodsDefiner
|
|
183
183
|
end
|
184
184
|
end
|
185
185
|
|
186
|
-
define_method("pre_#{
|
186
|
+
define_method("pre_#{phase}?") do
|
187
187
|
klass_stages[stage] < klass_stages[delimiters.first] unless cancelled?
|
188
188
|
end
|
189
189
|
|
190
|
-
define_method("past_#{
|
190
|
+
define_method("past_#{phase}?") do
|
191
191
|
klass_stages[stage] > klass_stages[delimiters.last] || cancelled?
|
192
192
|
end
|
193
193
|
end
|
@@ -1,22 +1,17 @@
|
|
1
1
|
module ActsAsLiving::ScopesDefiner
|
2
2
|
def self.call(klass)
|
3
3
|
klass.class_eval do
|
4
|
-
stages.each do |stage
|
5
|
-
scope "past_#{stage}", -> { where('stage >= ?',
|
6
|
-
scope "pre_#{stage}", -> { where('stage < ?',
|
7
|
-
scope "not_#{stage}", -> { where.not(stage: stage) }
|
4
|
+
stages.each do |stage,|
|
5
|
+
scope "past_#{stage}", -> { where('stage >= ?', stages_enum[stage]) }
|
6
|
+
scope "pre_#{stage}", -> { where('stage < ?', stages_enum[stage]) }
|
8
7
|
end
|
9
8
|
|
10
9
|
scope :cancelled, -> { where('stage < 0') }
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
scope period, lambda {
|
17
|
-
where('stage >= ? AND stage <= ?', stages[delimiters.first], stages[delimiters.second])
|
18
|
-
}
|
19
|
-
end
|
11
|
+
phases.each do |phase, delimiters|
|
12
|
+
scope phase, lambda {
|
13
|
+
where(stage: delimiters)
|
14
|
+
}
|
20
15
|
end
|
21
16
|
end
|
22
17
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_living
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guilherme Andrade
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|