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 +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/schema/deep_copy.rb +9 -3
- data/lib/schema/utils.rb +11 -1
- data/lib/schema/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1a95ca01d369cc20699a43f7a13b46fe567768c6ba5b8281cfb12800c56324e0
|
|
4
|
+
data.tar.gz: c185ad7251b43193473da560d837bd4f87fc00558c540e635fa6618a8719773f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
|
data/lib/schema/deep_copy.rb
CHANGED
|
@@ -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
|
-
|
|
20
|
-
next unless
|
|
19
|
+
copy_instance_variable_from(source, field_options[:instance_variable])
|
|
20
|
+
next unless field_options[:association] && field_options[:default]
|
|
21
21
|
|
|
22
|
-
|
|
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]}
|
|
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
|
)
|
data/lib/schema/version.rb
CHANGED