schema-model 0.9.0 → 0.9.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: bd3614644a664aa647cc01d0ae8032a4f08d3523f0377b9e92f2c34597228815
4
- data.tar.gz: 2f6c67150e5473230f8660cc21d7a7f26a2351dbc18f05b5754578c33cf521a3
3
+ metadata.gz: 1a95ca01d369cc20699a43f7a13b46fe567768c6ba5b8281cfb12800c56324e0
4
+ data.tar.gz: c185ad7251b43193473da560d837bd4f87fc00558c540e635fa6618a8719773f
5
5
  SHA512:
6
- metadata.gz: 28674549ae35fc72fa413a59aa87a20d72ed752ee56688d657bb61911a8d032308b3fc44908bd4c2702f7b86c261519801bf86c7751cd3b40c9364fdfce32bb4
7
- data.tar.gz: 5da6fcb9b0a79b21f926340d16486e4a5f8774725c1ca9cf3a58e3bbf996cee2856df0f84ad74acd4345dac1b999c1dcf09e41cfacf5f158819f13e78e432084
6
+ metadata.gz: e0e993ff5247dcb1acd76acbecaa2f0b65fcdf30e94d4342c8f362bc2ce0c87edf8ca2c511e35cf791a9150be29ff3f6f633f0b8d815ed7c3ae08dfff71d50f5
7
+ data.tar.gz: 34c05bb3bb1399be9c9d060617ad41cfcf8c2714c094097c5868fd52b56525c3be2e59af5be28ee28a5369e3e254267c389b40b496011ca8213350168c3ea7d6
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.9.1](https://github.com/dougyouch/schema/compare/v0.9.0...v0.9.1) (2026-10-04)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * **associations:** keep association defaults out of the set values ([3d90df3](https://github.com/dougyouch/schema/commit/3d90df3f8e8fa0b5da75cb313137d76a49106091))
9
+
3
10
  ## [0.9.0](https://github.com/dougyouch/schema/compare/v0.8.0...v0.9.0) (2026-10-04)
4
11
 
5
12
 
@@ -16,13 +16,19 @@ module Schema
16
16
  self.class.schema.each_value do |field_options|
17
17
  next if field_options[:alias_of]
18
18
 
19
- ivar = field_options[:instance_variable]
20
- next unless source.instance_variable_defined?(ivar)
19
+ copy_instance_variable_from(source, field_options[:instance_variable])
20
+ next unless field_options[:association] && field_options[:default]
21
21
 
22
- instance_variable_set(ivar, ::Schema::Utils.deep_dup_value(source.instance_variable_get(ivar)))
22
+ copy_instance_variable_from(source, ::Schema::Utils.association_default_instance_variable(field_options))
23
23
  end
24
24
  end
25
25
 
26
+ def copy_instance_variable_from(source, ivar)
27
+ return unless source.instance_variable_defined?(ivar)
28
+
29
+ instance_variable_set(ivar, ::Schema::Utils.deep_dup_value(source.instance_variable_get(ivar)))
30
+ end
31
+
26
32
  def copy_parsing_errors_from(source)
27
33
  @parsing_errors = nil
28
34
  ::Schema::Utils.parsing_error_pairs(source.parsing_errors).each do |attribute, message|
data/lib/schema/utils.rb CHANGED
@@ -108,7 +108,15 @@ module Schema
108
108
  )
109
109
  end
110
110
 
111
+ # where an association's default is kept once read, separate from the value set from the input
112
+ def association_default_instance_variable(options)
113
+ "#{options[:instance_variable]}_default"
114
+ end
115
+
116
+ # the default is memoized so changes to it stick, but in its own instance variable, so reading
117
+ # it doesn't make the association count as set (set_attribute_values, not_set?, inspect)
111
118
  def add_association_default_methods(kls, options)
119
+ default_instance_variable = association_default_instance_variable(options)
112
120
  kls.class_eval(
113
121
  <<-STR, __FILE__, __LINE__ + 1
114
122
  def #{options[:default_method]}
@@ -116,7 +124,9 @@ module Schema
116
124
  end
117
125
 
118
126
  def #{options[:getter]}
119
- #{options[:instance_variable]} ||= #{options[:default_method]}
127
+ return #{options[:instance_variable]} unless #{options[:instance_variable]}.nil?
128
+
129
+ #{default_instance_variable} ||= #{options[:default_method]}
120
130
  end
121
131
  STR
122
132
  )
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Schema
4
4
  # Gem version, bumped by release-please
5
- VERSION = '0.9.0'
5
+ VERSION = '0.9.1'
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: schema-model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Doug Youch