acts_as_living 0.1.10 → 0.1.15

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: 371a3643108cd762003a4150652a0f12e0853043e3dd4070fe7482c4ea0894dd
4
- data.tar.gz: 50d91c499af84693c4dac7f76e5cd8fef9f0cb92bf7328d09c9819fac9c7bd1f
3
+ metadata.gz: 12b6a909f4824398a5021fc625010ea556647fcb0997b74f4e62b2783be69305
4
+ data.tar.gz: 7c8b6524858879dcc73fac600f0aa50530302eb7ade4c17a4d4f6af9b284dd85
5
5
  SHA512:
6
- metadata.gz: 1527dc11a5f19f24b97bcf15a735898098f183f607419d1fa37541a0ecd42855674cea8c285eb17cf9ddf5d8faa30be8c154af58c18fa4893a0dc8444eb29cbd
7
- data.tar.gz: eccbaf60b93a8b4e81e3a1aa7769eb59514f08099493307dcd965ce50d5000d4b7ca81b3a56997dde273d1a0d2f2d69e5262ce2b625203434500fe1fd09fbae0
6
+ metadata.gz: 23499a06971844d813f54856a6b987d734d7ce6a9545d81226a8ad4e68e73da1375b91fe6741509fbeb282c05b02a1b78f5e8ee9b631557f4c59aa3ff3919a9d
7
+ data.tar.gz: b1d2d9c72c27cf11ad9f956f141e235068777f9878cb77bfd12d2452d3cbae4bbb0723e4ce8ad33190cbddaddac690bd765c49d6367fb134f53f44b24c0ce1ee
@@ -18,3 +18,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
18
18
  ## [0.1.10] - 2020-07-13
19
19
  ### Fixed
20
20
  - Bugs in phase scopes
21
+
22
+
23
+ ## [0.1.13] - 2020-07-13
24
+ ### Fixed
25
+ - fix SQL query for phases
@@ -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
@@ -6,7 +6,7 @@ module ActsAsLiving::ValidationsDefiner
6
6
  validates :stage, presence: true
7
7
 
8
8
  validate :stage_progression, on: :update, if: :stage_changed?
9
- validate :initialized_stage, on: :create, if: :stage_changed?
9
+ validate :stage_is_first_stage, on: :create, if: :stage_changed?
10
10
  end
11
11
  end
12
12
 
@@ -23,10 +23,10 @@ module ActsAsLiving::ValidationsDefiner
23
23
  errors.add(:stage, message)
24
24
  end
25
25
 
26
- def initialized_stage
27
- return if stage == self.class.initial_stage
26
+ def stage_is_first_stage
27
+ return if stage == self.class.first_stage
28
28
 
29
- errors.add(:stage, "Contract has to be initialized with '#{self.class.initial_stage}' stage")
29
+ errors.add(:stage, "Contract has to be initialized with '#{self.class.first_stage}' stage")
30
30
  end
31
31
  end
32
32
  end
@@ -1,3 +1,3 @@
1
1
  module ActsAsLiving
2
- VERSION = "0.1.10"
2
+ VERSION = "0.1.15"
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.10
4
+ version: 0.1.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guilherme Andrade