subroutine 2.3.0 → 2.3.1

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: a130a9c00d47631ee67621f3772ff5d050c348af94c9ec99a3ef4d90f0164079
4
- data.tar.gz: d7c099c1c586bfaf516955b1f94aa86188fbbe0194e42021d0f0191341efb482
3
+ metadata.gz: 0a85a75ee28c2c27b1d144059b1af01681aee27987ca2fdad9a0736b2270c824
4
+ data.tar.gz: 73bf392120764aa30da22c18b756ea8483f35b34e14e473fae6f7d495a4cbc9f
5
5
  SHA512:
6
- metadata.gz: ffa8be2183e84ad07c523251c499673a169f7b9968d79164f7662082ffc9497027f4344cb12fda6b602aaf2b6884a8be17690a58448f50138f4fb547f9d6e0cf
7
- data.tar.gz: c6130d737e8860e05d529e679e4a2f2be2de3f7114da5e97c5f8d3844463f3fc6f9e3a2f23da50891282989adcbd08759be9f243ff3aaf25adc978255cd18d43
6
+ metadata.gz: ea38c80c4bbf80eb1763f1052b5f0a906268b1eb6416bcd6e4f2f39a678af16395555ddc02b56867671413076680fb65343d7462974e594f112e8cdb2136f52b
7
+ data.tar.gz: b5590640ea893a227ef850fb052fb04cac6d46ccc0af2cb33b7b86972518c1b5b7988114fab0faa6472b215f8f927825c9699a08266fd6713ed8c84a88846065
@@ -60,7 +60,7 @@ module Subroutine
60
60
  end
61
61
 
62
62
  def build_foreign_key_field
63
- build_child_field(foreign_key_method, type: :foreign_key, foreign_key_type: determine_foreign_key_type)
63
+ build_child_field(foreign_key_method, type: :foreign_key, foreign_key_type: -> { determine_foreign_key_type })
64
64
  end
65
65
 
66
66
  def build_foreign_type_field
@@ -90,13 +90,15 @@ module Subroutine
90
90
  # TODO: Make this logic work for polymorphic associations.
91
91
  return if polymorphic?
92
92
 
93
- klass = inferred_foreign_type&.constantize
94
- if klass && klass.respond_to?(:type_for_attribute)
95
- case klass.type_for_attribute(find_by)&.type&.to_sym
96
- when :string
97
- :string
98
- else
99
- :integer
93
+ @determined_foreign_type ||= begin
94
+ klass = inferred_foreign_type&.constantize
95
+ if klass && klass.respond_to?(:type_for_attribute)
96
+ case klass.type_for_attribute(find_by)&.type&.to_sym
97
+ when :string
98
+ :string
99
+ else
100
+ :integer
101
+ end
100
102
  end
101
103
  end
102
104
  end
@@ -66,6 +66,7 @@ end
66
66
  ::Subroutine::TypeCaster.register :foreign_key do |value, options = {}|
67
67
  next nil if value.blank?
68
68
 
69
+ next ::Subroutine::TypeCaster.cast(value, type: options[:foreign_key_type].call) if options[:foreign_key_type].respond_to?(:call)
69
70
  next ::Subroutine::TypeCaster.cast(value, type: options[:foreign_key_type]) if options[:foreign_key_type]
70
71
  next ::Subroutine::TypeCaster.cast(value, type: :integer) if options[:name] && options[:name].to_s.end_with?("_id")
71
72
 
@@ -4,7 +4,7 @@ module Subroutine
4
4
 
5
5
  MAJOR = 2
6
6
  MINOR = 3
7
- PATCH = 0
7
+ PATCH = 1
8
8
  PRE = nil
9
9
 
10
10
  VERSION = [MAJOR, MINOR, PATCH, PRE].compact.join(".")
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: subroutine
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Nelson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-07 00:00:00.000000000 Z
11
+ date: 2023-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel