acts_as_living 0.1.4 → 0.1.5
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: ac1707ac917d7ca82291b1653915c2c3000147c96d443500b30a6fa9788551b1
|
4
|
+
data.tar.gz: ec6655308b3868412dfc7bc83b14e50a76c515d4e60906df6afc0af7fd59a376
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a37603ec1613cb1129b8b2778bac79d735e81ec8e76587f867bce38222a67820973d453e4c64b6f29b93cf4c25557a6a6296591923c6e8c1dac9952240b90fe
|
7
|
+
data.tar.gz: 2c7d3c92eec9bbc6e25e6e8df18741ce016232622ac13eb70c3afabc909fd731512cd0138507ab7326848398c89737a51e54731f6ec6950d3e031b96f430098f
|
@@ -5,9 +5,9 @@ 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:, spread:, column:)
|
9
9
|
@stage_keys = keys
|
10
|
-
@
|
10
|
+
@phases = phases
|
11
11
|
@locked_stages = lock_on
|
12
12
|
@death = death
|
13
13
|
@spread = spread
|
@@ -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
|
@@ -9,11 +9,11 @@ module ActsAsLiving::ScopesDefiner
|
|
9
9
|
|
10
10
|
scope :cancelled, -> { where('stage < 0') }
|
11
11
|
|
12
|
-
@
|
12
|
+
@phases.each do |phase, delimiters|
|
13
13
|
if delimiters.length == 1
|
14
|
-
scope
|
14
|
+
scope phase, -> { where(stage: delimiters.first) }
|
15
15
|
else
|
16
|
-
scope
|
16
|
+
scope phase, lambda {
|
17
17
|
where('stage >= ? AND stage <= ?', stages[delimiters.first], stages[delimiters.second])
|
18
18
|
}
|
19
19
|
end
|