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: 87b4c93d1a35a495a858bfbc9233dcc51ddbc2ec78f87f2d0bdf9e26aeecda1e
4
- data.tar.gz: c1cd8bfd44adb565e05300d9e2f5e47c5f48e2812785001f669a43d9ab8a5995
3
+ metadata.gz: ac1707ac917d7ca82291b1653915c2c3000147c96d443500b30a6fa9788551b1
4
+ data.tar.gz: ec6655308b3868412dfc7bc83b14e50a76c515d4e60906df6afc0af7fd59a376
5
5
  SHA512:
6
- metadata.gz: b08703608fc4b3f7f95c3a0bfb28fb33dfef1467ba93b1a6cc7e1dbc98d5c626fab2c2351c47297eb91b9d37e7590f16c0e4b164ffe370f30ce98c3817667864
7
- data.tar.gz: 742a2ea7875ce18ec0bd03d42f774485005aa3adf508a12944ff97f9491b89516e52d9f073d12262e74d664434f858ecc28f47ddcadc4858a732fa20d6515e3b
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, periods:, lock_on:, death:, spread:, column:)
8
+ def acts_as_living(keys, phases:, lock_on:, death:, spread:, column:)
9
9
  @stage_keys = keys
10
- @periods = periods
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 period of the acts_as_living
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(:period_change)
22
+ # callbacks_for(:phase_change)
23
23
  # stage_keys.each(&method(:stage_callbacks_for))
24
- # @periods.keys.each(&method(:lifeperiod_callbacks_for))
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
- # period_changed? ? run_period_callbacks { binding.pry; 'hey'; super(*args) } : super(*args)
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
- # period_changed? ? run_period_callbacks { binding.pry; 'hey'; super(*args) } : super(*args)
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 run_period_callbacks(&block)
53
- # _run_period_change_callbacks do
54
- # _run_period_started_callbacks do
55
- # _run_period_ended_callbacks(&block)
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 _run_period_started_callbacks(&block)
61
- # periods_started.inject(block) do |blk, period|
62
- # _run_period_started_callbacks(period, &blk)
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 _run_period_ended_callbacks(&block)
67
- # periods_ended.inject(block) do |blk, period|
68
- # _run_period_ended_callbacks(period, &blk)
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 _run_period_started_callbacks(period, &block)
73
- # run_callbacks("#{period}_started".to_sym, &block)
72
+ # def _run_phase_started_callbacks(phase, &block)
73
+ # run_callbacks("#{phase}_started".to_sym, &block)
74
74
  # end
75
75
 
76
- # def _run_period_ended_callbacks(period, &block)
77
- # run_callbacks("#{period}_ended".to_sym, &block)
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 lifeperiod_callbacks_for(period)
83
- # define_callback_methods_for("#{period}_started".to_sym)
84
- # define_callback_methods_for("#{period}_ended".to_sym)
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
- @periods.each(&method(:define_period_queries))
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 klass_periods_with_ranges
68
- self.class.periods_with_ranges
67
+ def klass_phases_with_ranges
68
+ self.class.phases_with_ranges
69
69
  end
70
70
 
71
- def klass_periods_for(stage)
72
- self.class.periods_for(stage)
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 periods
86
- klass_periods_for(stage)
85
+ def phases
86
+ klass_phases_for(stage)
87
87
  end
88
88
 
89
- def period_changed?
90
- klass_periods_for(stage) != klass_periods_for(stage_was)
89
+ def phase_changed?
90
+ klass_phases_for(stage) != klass_phases_for(stage_was)
91
91
  end
92
92
 
93
- def periods_started
94
- klass_periods_for(stage) - klass_periods_for(stage_was)
93
+ def phases_started
94
+ klass_phases_for(stage) - klass_phases_for(stage_was)
95
95
  end
96
96
 
97
- def periods_ended
98
- klass_periods_for(stage_was) - klass_periods_for(stage)
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 periods_with_ranges
159
- @periods.map(&method(:to_period_with_range)).to_h
158
+ def phases_with_ranges
159
+ @phases.map(&method(:to_phase_with_range)).to_h
160
160
  end
161
161
 
162
- def to_period_with_range(period, delimiter)
163
- [period, (stages[delimiter.first]..stages[delimiter.last])]
162
+ def to_phase_with_range(phase, delimiter)
163
+ [phase, (stages[delimiter.first]..stages[delimiter.last])]
164
164
  end
165
165
 
166
- def periods
167
- @periods
166
+ def phases
167
+ @phases
168
168
  end
169
169
 
170
- def periods_for(stage)
171
- periods_with_ranges.keys.select do |period|
172
- periods_with_ranges[period].include? stages[stage]
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 define_period_queries(period, delimiters)
177
- define_method("#{period}?") do
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_#{period}?") do
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_#{period}?") do
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
- @periods.each do |period, delimiters|
12
+ @phases.each do |phase, delimiters|
13
13
  if delimiters.length == 1
14
- scope period, -> { where(stage: delimiters.first) }
14
+ scope phase, -> { where(stage: delimiters.first) }
15
15
  else
16
- scope period, lambda {
16
+ scope phase, lambda {
17
17
  where('stage >= ? AND stage <= ?', stages[delimiters.first], stages[delimiters.second])
18
18
  }
19
19
  end
@@ -1,3 +1,3 @@
1
1
  module ActsAsLiving
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_living
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guilherme Andrade