activeentity 0.0.1.beta17 → 6.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -86,16 +86,31 @@ module ActiveEntity
86
86
  @load_schema_invoked = true
87
87
  end
88
88
 
89
- def reload_schema_from_cache
90
- @attribute_types = nil
91
- @default_attributes = nil
92
- @attributes_builder = nil
93
- @schema_loaded = false
94
- @load_schema_invoked = false
95
- @attribute_names = nil
96
- @yaml_encoder = nil
97
- direct_descendants.each do |descendant|
98
- descendant.send(:reload_schema_from_cache)
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 < ActiveModel::Type::Registry
9
- def add_modifier(options, klass, **args)
10
- registrations << DecorationRegistration.new(options, klass, **args)
6
+ class Registry # :nodoc:
7
+ def initialize
8
+ @registrations = []
11
9
  end
12
10
 
13
- private
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
- def registration_klass
16
- Registration
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 do |attribute, message|
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
- record.errors.details[attribute].each do |error|
282
- errors.details[reflection_attribute] << error
283
- errors.details[reflection_attribute].uniq!
284
- end
285
- end
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!(value: value))
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[normalized_attribute].concat r.errors.messages[key]
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[normalized_attribute].concat r.errors.messages[attr]
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
@@ -38,6 +38,7 @@ module ActiveEntity
38
38
  extend ActiveSupport::Autoload
39
39
 
40
40
  autoload :Base
41
+ autoload :Callbacks
41
42
  autoload :Core
42
43
  autoload :Enum
43
44
  autoload :Inheritance
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: 0.0.1.beta17
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: 2020-04-13 00:00:00.000000000 Z
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: '7.0'
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: '7.0'
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: '7.0'
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: '7.0'
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: 1.3.1
151
+ version: '0'
152
152
  requirements: []
153
- rubygems_version: 3.1.2
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: []