acts_as_living 0.1.3 → 0.1.8
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 +2 -3
- data/lib/acts_as_living/callbacks_definer.rb +22 -22
- data/lib/acts_as_living/methods_definer.rb +26 -26
- data/lib/acts_as_living/railtie.rb +1 -0
- data/lib/acts_as_living/scopes_definer.rb +5 -9
- 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: 22753ff3ef8b8cea17388e829a27a35d7df50f149d2122e0eb78bb03adfd7268
|
4
|
+
data.tar.gz: 88bd7bc883536421e6eb8253f780caa759156015ae5fe077ec366c5708289846
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5bd734f95d3fafce29a5b4b8bffb26a630f77d4b19cecf3dbbb069fc14ec9bff3fbab5a65f0b5ecae26a866baf7c6a6cce7a1531470b5b379ec4989313caab95
|
7
|
+
data.tar.gz: 9d61ea225e1626724de291ddd01410e3d07b75df945b73c3b7b176cf4417ff8b743d8e43258056f4a0215ba5886b742a4ea13ab5be52d708faa3eb1c8841c500
|
data/Changelog.md
CHANGED
@@ -5,13 +5,12 @@ 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
|
@@ -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,18 @@
|
|
1
1
|
module ActsAsLiving::ScopesDefiner
|
2
2
|
def self.call(klass)
|
3
3
|
klass.class_eval do
|
4
|
+
byebug
|
4
5
|
stages.each do |stage, _num|
|
5
6
|
scope "past_#{stage}", -> { where('stage >= ?', stages[stage]) }
|
6
7
|
scope "pre_#{stage}", -> { where('stage < ?', stages[stage]) }
|
7
|
-
scope "not_#{stage}", -> { where.not(stage: stage) }
|
8
8
|
end
|
9
9
|
|
10
10
|
scope :cancelled, -> { where('stage < 0') }
|
11
11
|
|
12
|
-
@
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
scope period, lambda {
|
17
|
-
where('stage >= ? AND stage <= ?', stages[delimiters.first], stages[delimiters.second])
|
18
|
-
}
|
19
|
-
end
|
12
|
+
@phases.each do |phase, delimiters|
|
13
|
+
scope phase, lambda {
|
14
|
+
where(stage: delimiters)
|
15
|
+
}
|
20
16
|
end
|
21
17
|
end
|
22
18
|
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.8
|
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
|