servitium 1.3.3 → 1.3.5
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/lib/servitium/context_model.rb +23 -0
- data/lib/servitium/rails8_value_dirty_compat.rb +20 -0
- data/lib/servitium/version.rb +1 -1
- data/lib/servitium.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8a0ef3ad8b27e23da12fb7e38523b6791067182326c4eb687ff783c04590a48b
|
|
4
|
+
data.tar.gz: 7db9f17e28035c835626d7a95b53566fcc970cee967753666ad6651ca5553005
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 21d99ac12c2a0b21d15c3344c1f25ccf01151a10516794485d7343e9d8b9940e7b555fc5fcd29c563c937d3810cd22cd747f551aca54d78db112a2dbc48c625e
|
|
7
|
+
data.tar.gz: d112f878db7d4f82e806d34805a80e5cd5cd28388d4e7a728f0c2b8d4e7af3cfb02fdbcf8b2a533977bc875d230b984ef1ef8151a4c904141c0656ccf3f8c4b7
|
|
@@ -56,8 +56,31 @@ module Servitium
|
|
|
56
56
|
def _destroy
|
|
57
57
|
end
|
|
58
58
|
|
|
59
|
+
# Rails 8 ActiveModel::Dirty expects attribute values to respond to +changed_in_place?+
|
|
60
|
+
# (e.g. when using NumericalityValidator). ActiveAttr stores raw values, so we ensure
|
|
61
|
+
# every value in @attributes responds to it. write_attribute covers normal writes;
|
|
62
|
+
# apply_defaults covers defaults (ActiveAttr writes those directly to @attributes).
|
|
63
|
+
def write_attribute(name, value)
|
|
64
|
+
ensure_changed_in_place!(value)
|
|
65
|
+
super
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def apply_defaults(defaults = attribute_defaults)
|
|
69
|
+
super
|
|
70
|
+
(@attributes || {}).each_value { |value| ensure_changed_in_place!(value) }
|
|
71
|
+
end
|
|
72
|
+
|
|
59
73
|
private
|
|
60
74
|
|
|
75
|
+
def ensure_changed_in_place!(value)
|
|
76
|
+
return if value.nil? || value.respond_to?(:changed_in_place?)
|
|
77
|
+
|
|
78
|
+
value.define_singleton_method(:changed_in_place?) { false }
|
|
79
|
+
rescue TypeError
|
|
80
|
+
# Integer, Float, Symbol, true, false, nil etc. can't get singleton methods;
|
|
81
|
+
# they use the class-level method from rails8_value_dirty_compat.
|
|
82
|
+
end
|
|
83
|
+
|
|
61
84
|
def validate_subcontexts
|
|
62
85
|
@subcontexts.each do |key, value|
|
|
63
86
|
errors.add(key, "invalid") unless [*value].find_all { |v| v.respond_to?(:invalid?) && v.invalid? }.empty?
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Rails 8 compatibility: ActiveModel::Dirty expects attribute values to respond to
|
|
4
|
+
# +changed_in_place?+. Value types (Integer, Float, Symbol, etc.) can't get
|
|
5
|
+
# singleton methods in Ruby, so we add the method at the class level here.
|
|
6
|
+
# Servitium/ActiveAttr context attributes use these types; without this, validations
|
|
7
|
+
# (e.g. NumericalityValidator) raise NoMethodError.
|
|
8
|
+
|
|
9
|
+
require "bigdecimal"
|
|
10
|
+
require "date"
|
|
11
|
+
|
|
12
|
+
[
|
|
13
|
+
String, Integer, Float, BigDecimal,
|
|
14
|
+
TrueClass, FalseClass, NilClass, Symbol,
|
|
15
|
+
Date, Time, Array, Hash
|
|
16
|
+
].each do |klass|
|
|
17
|
+
next if klass.method_defined?(:changed_in_place?)
|
|
18
|
+
|
|
19
|
+
klass.define_method(:changed_in_place?) { false }
|
|
20
|
+
end
|
data/lib/servitium/version.rb
CHANGED
data/lib/servitium.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: servitium
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.3.
|
|
4
|
+
version: 1.3.5
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tom de Grunt
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-01-31 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: active_attr
|
|
@@ -281,6 +281,7 @@ files:
|
|
|
281
281
|
- lib/servitium/i18n.rb
|
|
282
282
|
- lib/servitium/rails.rb
|
|
283
283
|
- lib/servitium/rails/railtie.rb
|
|
284
|
+
- lib/servitium/rails8_value_dirty_compat.rb
|
|
284
285
|
- lib/servitium/scoped_attributes.rb
|
|
285
286
|
- lib/servitium/service.rb
|
|
286
287
|
- lib/servitium/service_active_job.rb
|