activeentity 0.0.1.beta17 → 6.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 +4 -4
- data/README.md +65 -3
- data/lib/active_entity/attribute_methods/before_type_cast.rb +5 -5
- data/lib/active_entity/attribute_methods/dirty.rb +168 -1
- data/lib/active_entity/attribute_methods/primary_key.rb +6 -8
- data/lib/active_entity/attribute_methods/query.rb +2 -6
- data/lib/active_entity/attribute_methods/read.rb +10 -12
- data/lib/active_entity/attribute_methods/write.rb +14 -20
- data/lib/active_entity/attribute_methods.rb +544 -12
- data/lib/active_entity/attributes.rb +1 -0
- data/lib/active_entity/core.rb +1 -0
- data/lib/active_entity/gem_version.rb +4 -4
- data/lib/active_entity/inheritance.rb +2 -2
- data/lib/active_entity/model_schema.rb +25 -10
- data/lib/active_entity/type/registry.rb +32 -12
- data/lib/active_entity/validate_embeds_association.rb +8 -13
- data/lib/active_entity/validations/subset.rb +1 -1
- data/lib/active_entity/validations/uniqueness_in_embeds.rb +4 -12
- data/lib/active_entity.rb +1 -0
- metadata +16 -16
@@ -86,16 +86,31 @@ module ActiveEntity
|
|
86
86
|
@load_schema_invoked = true
|
87
87
|
end
|
88
88
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
descendant
|
89
|
+
if ActiveSupport::VERSION::MAJOR >= 7
|
90
|
+
def reload_schema_from_cache
|
91
|
+
@attribute_types = nil
|
92
|
+
@default_attributes = nil
|
93
|
+
@attributes_builder = nil
|
94
|
+
@schema_loaded = false
|
95
|
+
@load_schema_invoked = false
|
96
|
+
@attribute_names = nil
|
97
|
+
@yaml_encoder = nil
|
98
|
+
subclasses.each do |descendant|
|
99
|
+
descendant.send(:reload_schema_from_cache)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
else
|
103
|
+
def reload_schema_from_cache
|
104
|
+
@attribute_types = nil
|
105
|
+
@default_attributes = nil
|
106
|
+
@attributes_builder = nil
|
107
|
+
@schema_loaded = false
|
108
|
+
@load_schema_invoked = false
|
109
|
+
@attribute_names = nil
|
110
|
+
@yaml_encoder = nil
|
111
|
+
direct_descendants.each do |descendant|
|
112
|
+
descendant.send(:reload_schema_from_cache)
|
113
|
+
end
|
99
114
|
end
|
100
115
|
end
|
101
116
|
end
|
@@ -1,20 +1,42 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require "active_model/type/registry"
|
4
|
-
|
5
3
|
module ActiveEntity
|
6
4
|
# :stopdoc:
|
7
5
|
module Type
|
8
|
-
class Registry
|
9
|
-
def
|
10
|
-
registrations
|
6
|
+
class Registry # :nodoc:
|
7
|
+
def initialize
|
8
|
+
@registrations = []
|
11
9
|
end
|
12
10
|
|
13
|
-
|
11
|
+
def initialize_copy(_other)
|
12
|
+
@registrations = @registrations.dup
|
13
|
+
end
|
14
|
+
|
15
|
+
def add_modifier(options, klass, **_args)
|
16
|
+
registrations << DecorationRegistration.new(options, klass)
|
17
|
+
end
|
14
18
|
|
15
|
-
|
16
|
-
|
19
|
+
def register(type_name, klass = nil, **options, &block)
|
20
|
+
unless block_given?
|
21
|
+
block = proc { |_, *args| klass.new(*args) }
|
22
|
+
block.ruby2_keywords if block.respond_to?(:ruby2_keywords)
|
17
23
|
end
|
24
|
+
registrations << Registration.new(type_name, block, **options)
|
25
|
+
end
|
26
|
+
|
27
|
+
def lookup(symbol, *args, **kwargs)
|
28
|
+
registration = find_registration(symbol, *args, **kwargs)
|
29
|
+
|
30
|
+
if registration
|
31
|
+
registration.call(self, symbol, *args, **kwargs)
|
32
|
+
else
|
33
|
+
raise ArgumentError, "Unknown type #{symbol.inspect}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
attr_reader :registrations
|
18
40
|
|
19
41
|
def find_registration(symbol, *args, **kwargs)
|
20
42
|
registrations
|
@@ -23,7 +45,7 @@ module ActiveEntity
|
|
23
45
|
end
|
24
46
|
end
|
25
47
|
|
26
|
-
class Registration
|
48
|
+
class Registration # :nodoc:
|
27
49
|
def initialize(name, block, override: nil)
|
28
50
|
@name = name
|
29
51
|
@block = block
|
@@ -55,7 +77,7 @@ module ActiveEntity
|
|
55
77
|
end
|
56
78
|
end
|
57
79
|
|
58
|
-
class DecorationRegistration < Registration
|
80
|
+
class DecorationRegistration < Registration # :nodoc:
|
59
81
|
def initialize(options, klass, **)
|
60
82
|
@options = options
|
61
83
|
@klass = klass
|
@@ -86,7 +108,5 @@ module ActiveEntity
|
|
86
108
|
end
|
87
109
|
end
|
88
110
|
|
89
|
-
class TypeConflictError < StandardError
|
90
|
-
end
|
91
111
|
# :startdoc:
|
92
112
|
end
|
@@ -268,21 +268,16 @@ module ActiveEntity
|
|
268
268
|
unless valid = record.valid?(context)
|
269
269
|
indexed_attribute = !index.nil? && (reflection.options[:index_errors] || ActiveEntity::Base.index_nested_attribute_errors)
|
270
270
|
|
271
|
-
record.errors.each
|
271
|
+
record.errors.group_by_attribute.each { |attribute, errors|
|
272
272
|
attribute = normalize_reflection_attribute(indexed_attribute, reflection, index, attribute)
|
273
|
-
errors[attribute] << message
|
274
|
-
errors[attribute].uniq!
|
275
|
-
end
|
276
|
-
|
277
|
-
record.errors.details.each_key do |attribute|
|
278
|
-
reflection_attribute =
|
279
|
-
normalize_reflection_attribute(indexed_attribute, reflection, index, attribute).to_sym
|
280
273
|
|
281
|
-
|
282
|
-
errors.
|
283
|
-
|
284
|
-
|
285
|
-
|
274
|
+
errors.each { |error|
|
275
|
+
self.errors.import(
|
276
|
+
error,
|
277
|
+
attribute: attribute
|
278
|
+
)
|
279
|
+
}
|
280
|
+
}
|
286
281
|
end
|
287
282
|
|
288
283
|
valid
|
@@ -18,7 +18,7 @@ module ActiveEntity
|
|
18
18
|
end
|
19
19
|
|
20
20
|
unless subset?(record, value)
|
21
|
-
record.errors.add(attribute, :non_subset, options.except(:in, :within).merge
|
21
|
+
record.errors.add(attribute, :non_subset, **options.except(:in, :within).merge(value: value))
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
@@ -48,26 +48,18 @@ module ActiveEntity
|
|
48
48
|
|
49
49
|
duplicate_records.each do |r|
|
50
50
|
if key.is_a? Symbol
|
51
|
-
r.errors.add(key, :duplicated, options)
|
51
|
+
r.errors.add(key, :duplicated, **options)
|
52
52
|
|
53
53
|
# Hack the record
|
54
54
|
normalized_attribute = normalize_attribute(attribute, indexed_attribute, association_or_value.index(r), key)
|
55
|
-
record.errors
|
56
|
-
record.errors[normalized_attribute].uniq!
|
57
|
-
|
58
|
-
record.errors.details[normalized_attribute.to_sym].concat r.errors.details[key]
|
59
|
-
record.errors.details[normalized_attribute.to_sym].uniq!
|
55
|
+
record.errors.import r.errors.where(key).first, attribute: normalized_attribute
|
60
56
|
elsif key.is_a? Array
|
61
57
|
key.each do |attr|
|
62
|
-
r.errors.add(attr, :duplicated, options)
|
58
|
+
r.errors.add(attr, :duplicated, **options)
|
63
59
|
|
64
60
|
# Hack the record
|
65
61
|
normalized_attribute = normalize_attribute(attribute, indexed_attribute, association_or_value.index(r), attr)
|
66
|
-
record.errors
|
67
|
-
record.errors[normalized_attribute].uniq!
|
68
|
-
|
69
|
-
record.errors.details[normalized_attribute.to_sym].concat r.errors.details[attr]
|
70
|
-
record.errors.details[normalized_attribute.to_sym].uniq!
|
62
|
+
record.errors.import r.errors.where(key).first, attribute: normalized_attribute
|
71
63
|
end
|
72
64
|
end
|
73
65
|
end
|
data/lib/active_entity.rb
CHANGED
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeentity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 6.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jasl
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '6.0'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: '
|
22
|
+
version: '8'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
|
-
- - "
|
27
|
+
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '6.0'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
32
|
+
version: '8'
|
33
33
|
- !ruby/object:Gem::Dependency
|
34
34
|
name: activemodel
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
|
-
- - "
|
37
|
+
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: '6.0'
|
40
40
|
- - "<"
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: '
|
42
|
+
version: '8'
|
43
43
|
type: :runtime
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
|
-
- - "
|
47
|
+
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
49
|
version: '6.0'
|
50
50
|
- - "<"
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version: '
|
52
|
+
version: '8'
|
53
53
|
description: Rails virtual model solution based on ActiveModel design for Rails 6+.
|
54
54
|
email:
|
55
55
|
- jasl9187@hotmail.com
|
@@ -135,7 +135,7 @@ homepage: https://github.com/jasl/activeentity
|
|
135
135
|
licenses:
|
136
136
|
- MIT
|
137
137
|
metadata: {}
|
138
|
-
post_install_message:
|
138
|
+
post_install_message:
|
139
139
|
rdoc_options: []
|
140
140
|
require_paths:
|
141
141
|
- lib
|
@@ -146,12 +146,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
146
146
|
version: 2.5.0
|
147
147
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
148
|
requirements:
|
149
|
-
- - "
|
149
|
+
- - ">="
|
150
150
|
- !ruby/object:Gem::Version
|
151
|
-
version:
|
151
|
+
version: '0'
|
152
152
|
requirements: []
|
153
|
-
rubygems_version: 3.
|
154
|
-
signing_key:
|
153
|
+
rubygems_version: 3.3.4
|
154
|
+
signing_key:
|
155
155
|
specification_version: 4
|
156
156
|
summary: Rails virtual model solution based on ActiveModel.
|
157
157
|
test_files: []
|