smart_enum 2.2.1 → 2.3.0

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: 7b509495447ff0f5652c258b272ce0ee0f37613b2c3e245a320677268cb4cb39
4
- data.tar.gz: 934e89507c312f351ae5ad1d4fed972e83477314b42a2e426f7c5c79b1de5f44
3
+ metadata.gz: 4d5e1b7ef5e308f04977da423a507a2b4410f37fd5598f1bf3e91ca1a62eccb6
4
+ data.tar.gz: 75ec6c25b5b250d087f32ced6f592010c0f58d4291edabf61d4699801f6c3d3b
5
5
  SHA512:
6
- metadata.gz: f55bf375b72f8fa189f3c9772300aafd571b458e96c40bc48647ab1c65f2ed7b4758c41082668c25ddcda3caf6812163a6bfa09da9128fa9f15dc2b28bb2c816
7
- data.tar.gz: 289a41a759595796b31f08f224bdd844d68e085e55b261ad4b9033ac72852e1d39a1d47cfbf48988e090939560c65a4e70ab4a130ddb492bccd6914c82af835c
6
+ metadata.gz: eb70f0475bb263cd313e64d83b953d0630ddc0667686658eaf3be2b71a428db3f31e6a3937198ca26a4f7a1b520c41306b7b6048bf3e84da5ee750e0057c87c2
7
+ data.tar.gz: 2f780b170aaab8ee794096c65767a1543dcbcdf5aa88841f39e80bee594c0fd59527a2d49c30c101943f7b8ef6b589a78adb3a0738d4f0c286fb49f9945e08e7
@@ -57,13 +57,13 @@ class SmartEnum
57
57
  end
58
58
  end
59
59
 
60
- def belongs_to_enum(association_name, class_name: nil, foreign_key: nil)
60
+ def belongs_to_enum(association_name, class_name: nil, foreign_key: nil, when_nil: nil)
61
61
  association_name = association_name.to_sym
62
62
  association = Association.new(self, association_name, class_name: class_name, foreign_key: foreign_key)
63
63
  enum_associations[association_name] = association
64
64
 
65
65
  define_method(association_name) do
66
- id_to_find = self.public_send(association.foreign_key)
66
+ id_to_find = self.public_send(association.foreign_key) || when_nil
67
67
  association.association_class[id_to_find]
68
68
  end
69
69
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class SmartEnum
4
- VERSION = "2.2.1"
4
+ VERSION = "2.3.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_enum
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Carl Brasic
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2019-04-16 00:00:00.000000000 Z
12
+ date: 2019-06-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
@@ -65,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
65
65
  version: '0'
66
66
  requirements: []
67
67
  rubyforge_project:
68
- rubygems_version: 2.7.4
68
+ rubygems_version: 2.7.6
69
69
  signing_key:
70
70
  specification_version: 4
71
71
  summary: Enums to replace database lookup tables