swifter_enum 0.9.4 → 0.9.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a0b96e6c66d225905968a0a5b44a921c1aa01c2d567a6ce215fa2021a88f64de
4
- data.tar.gz: f5a824043a596b0587195bc415784f411005e1d5b989ac0afa5a14a0f9b69893
3
+ metadata.gz: bc0cc85f030b595af2b26f01beabc39a89ca0b93225e15f89dbe4bb42a584769
4
+ data.tar.gz: 4b59b30641a70706fd33cf194ae9d3fb74dc9bb79431dcaf125be229df73853e
5
5
  SHA512:
6
- metadata.gz: 4b480834e9d30c76b3a59b113247a7ba41f51699af40be97d1183236dd33ec5fe49d231f1b4b29b2de15d8ce567ba98d3d6118a6811dd124994adc4ed7cb3440
7
- data.tar.gz: a3b43c3c21afcbab79ce070b0156298835a8f61c369411eb14271ffd72db48aaadb8906ebeee7b80af0bbaa592248636724a14c91c187fbeaffeb6988d1c0941
6
+ metadata.gz: e76f0fdc3fc9fdce9f4765ec015c1081f24b7a39ae406969156e40912f5265174050aca81167d6d5631540e26531f604f7b80ad0cd7ae4c3efb63413f0f2cf1c
7
+ data.tar.gz: 95e05c2e64a25feb0de2c20b62cca2faa522bd55b173b8c592cb56ed30b847dc645391dae8da7dfb69dfe3d555feade28f3968004dc2b84b6337f204abb3f9dd
data/CHANGELOG.md CHANGED
@@ -19,4 +19,8 @@
19
19
 
20
20
  ## [0.9.4]
21
21
 
22
- - Add 'all_cases'
22
+ - Add 'all_cases'
23
+
24
+ ## [0.9.5]
25
+
26
+ - Fix translation method when value is nil (returns nil)
@@ -16,7 +16,8 @@ module SwifterEnum
16
16
 
17
17
  # Define getter method
18
18
  define_method(enum_name) do
19
- enum_klass.new(read_attribute(enum_name))
19
+ attribute = read_attribute(enum_name)
20
+ enum_klass.new(attribute) if attribute.present?
20
21
  end
21
22
 
22
23
  # Define setter method
@@ -3,18 +3,18 @@ require "active_model"
3
3
  module SwifterEnum
4
4
  class SwifterEnumValidator < ActiveModel::EachValidator
5
5
  def validate_each(record, attribute, a_value)
6
- if !a_value.is_a?(SwifterEnum::Base) || a_value.instance_of?(SwifterEnum::Base)
7
- record.errors.add(attribute, "#{a_value.value} is not a valid subclass of SwifterEnum")
8
- end
9
-
10
- if a_value.value.nil?
6
+ if a_value.nil?
11
7
  return if options[:allow_nil]
12
8
 
13
9
  record.errors.add(attribute, "nil value for #{attribute} is not allowed")
10
+ return
11
+ end
12
+
13
+ if !a_value.is_a?(SwifterEnum::Base) || a_value.instance_of?(SwifterEnum::Base)
14
+ record.errors.add(attribute, "#{a_value.value} is not a valid subclass of SwifterEnum")
14
15
  end
15
16
 
16
17
  unless a_value.class.values.key?(a_value.value)
17
- # binding.b
18
18
  record.errors.add(attribute, "#{a_value.value} is not a valid #{attribute} type")
19
19
  end
20
20
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SwifterEnum
4
- VERSION = "0.9.4"
4
+ VERSION = "0.9.6"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: swifter_enum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.4
4
+ version: 0.9.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Jonson
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-03-13 00:00:00.000000000 Z
11
+ date: 2024-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord