acts_as_living 0.1.9 → 0.1.14

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: 6623143eb72b9906a984375aa0a2e67d30ae49fd10c17e54d89569b52333ea0e
4
- data.tar.gz: 2778b40bf555acea1efce2ed87c199c882a9222ccdce8cde905735903125243d
3
+ metadata.gz: 73d33885449af7caca352c2349ec8bb1897f01b6b3d6906b8dd414d4dda6d6c9
4
+ data.tar.gz: e8fc368946103d716e0c84132f9f84662f21ddbf392237de7f2309801c8f0f9b
5
5
  SHA512:
6
- metadata.gz: 3327015d9f2002c6d24e641d872d93098a53abf251ced9e2f51a1156e9524efa1f628896fd7ac4c61061e1f9cb53856628402cae7d22f0b62136becd6f4dde45
7
- data.tar.gz: 007a78047238697bfaeb646bc4ec7b9dfd2c41861429f4b101acb4d544624851d99e99798aa52b3897ed2443c7f49bb3e5f2010b375c442c6e2f5643a648a838
6
+ metadata.gz: 5fca0d7f19165ac60768f58cb92c29f516b7746a8078fcadfb13176d5b7899d3a5acfe8018f638a0ea31256e89cbc24075aee378f4df5f33a0e9c7365612d05e
7
+ data.tar.gz: 07e876c5194830496f4bccbd9a6e849e59d102bc7607105152acbe01e197a6978f0194a2c1071f797a5b130bfb8e2ea5b6eda041d2ba2df863e50063382b3d73
@@ -13,3 +13,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
13
13
  ## [0.1.7] - 2020-07-13
14
14
  ### Fixed
15
15
  - Stage Scopes
16
+
17
+
18
+ ## [0.1.10] - 2020-07-13
19
+ ### Fixed
20
+ - Bugs in phase scopes
21
+
22
+
23
+ ## [0.1.13] - 2020-07-13
24
+ ### Fixed
25
+ - fix SQL query for phases
@@ -16,8 +16,9 @@ module ActsAsLiving::ActsAsLiving
16
16
  end
17
17
 
18
18
  def run_definers
19
- ActsAsLiving::EnumDefiner.call(self)
19
+ # needs to be imported first
20
20
  ActsAsLiving::MethodsDefiner.call(self)
21
+ ActsAsLiving::EnumDefiner.call(self)
21
22
  ActsAsLiving::ScopesDefiner.call(self)
22
23
  ActsAsLiving::ValidationsDefiner.call(self)
23
24
  end
@@ -5,7 +5,7 @@ module ActsAsLiving::EnumDefiner
5
5
  klass.class_eval do
6
6
  extend ClassMethods
7
7
 
8
- enum @column => enum_options
8
+ enum @column => stages_enum
9
9
  end
10
10
  end
11
11
 
@@ -52,8 +52,8 @@ module ActsAsLiving::MethodsDefiner
52
52
  self.class.dying?(stage)
53
53
  end
54
54
 
55
- def newborn?
56
- self.class.newborn?(stage)
55
+ def first_stage?
56
+ self.class.first_stage?(stage)
57
57
  end
58
58
 
59
59
  def dead?
@@ -105,7 +105,7 @@ module ActsAsLiving::MethodsDefiner
105
105
  end
106
106
 
107
107
  def stage_keys
108
- stages.keys
108
+ @stage_keys
109
109
  end
110
110
 
111
111
  def stages_after(stage)
@@ -115,7 +115,7 @@ module ActsAsLiving::MethodsDefiner
115
115
  end
116
116
 
117
117
  def stages_before(stage)
118
- return [] if newborn?(stage)
118
+ return [] if first_stage?(stage)
119
119
 
120
120
  index = stage_keys.find_index(stage)
121
121
  stage_keys[0...index]
@@ -129,38 +129,38 @@ module ActsAsLiving::MethodsDefiner
129
129
  end
130
130
 
131
131
  def stage_before(stage)
132
- return if newborn?(stage)
132
+ return if first_stage?(stage)
133
133
 
134
134
  index = stage_keys.find_index(stage)
135
135
  stage_keys[index - 1]
136
136
  end
137
137
 
138
- def final_stage
139
- stage_keys.last
138
+ def last_stage
139
+ (stage_keys - %i[cancelled]).last
140
140
  end
141
141
 
142
- def dying?(stage)
143
- final_stage == stage
142
+ def last_stage?(stage)
143
+ last_stage == stage
144
144
  end
145
145
 
146
- def newborn_stage
147
- stages.key(0)
146
+ def first_stage_stage
147
+ (stage_keys - %i[cancelled]).first
148
148
  end
149
149
 
150
- def death
151
- @death
150
+ def first_stage?(stage)
151
+ first_stage_stage == stage
152
152
  end
153
153
 
154
- def newborn?(stage)
155
- initial_stage == stage
154
+ def death
155
+ @death
156
156
  end
157
157
 
158
158
  def phases_with_ranges
159
- @phases.map(&method(:to_phase_with_range)).to_h
159
+ phases.map(&method(:to_phase_with_range)).to_h
160
160
  end
161
161
 
162
162
  def to_phase_with_range(phase, delimiter)
163
- [phase, (stages[delimiter.first]..stages[delimiter.last])]
163
+ [phase, (stages_enum[delimiter.first]..stages_enum[delimiter.last])]
164
164
  end
165
165
 
166
166
  def phases
@@ -1,16 +1,17 @@
1
1
  module ActsAsLiving::ScopesDefiner
2
2
  def self.call(klass)
3
3
  klass.class_eval do
4
- stages.each do |stage,|
4
+ stage_keys.each do |stage|
5
5
  scope "past_#{stage}", -> { where('stage >= ?', stages_enum[stage]) }
6
6
  scope "pre_#{stage}", -> { where('stage < ?', stages_enum[stage]) }
7
7
  end
8
8
 
9
9
  scope :cancelled, -> { where('stage < 0') }
10
10
 
11
- phases.each do |phase, delimiters|
11
+ phases.each do |phase, phase_stages|
12
12
  scope phase, lambda {
13
- where(stage: delimiters)
13
+ phase_stages_integers = phase_stages.map { |stage| stages_enum[stage] }
14
+ where(stage: phase_stages_integers)
14
15
  }
15
16
  end
16
17
  end
@@ -1,3 +1,3 @@
1
1
  module ActsAsLiving
2
- VERSION = "0.1.9"
2
+ VERSION = "0.1.14"
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.9
4
+ version: 0.1.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guilherme Andrade