activeentity 0.0.1.beta5 → 0.0.1.beta6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -1
- data/lib/active_entity/associations/embedded/builder/association.rb +9 -4
- data/lib/active_entity/associations/embedded/builder/collection_association.rb +6 -4
- data/lib/active_entity/associations/embedded/collection_association.rb +11 -1
- data/lib/active_entity/associations/embedded/embeds_one_association.rb +11 -5
- data/lib/active_entity/gem_version.rb +1 -1
- data/lib/active_entity/reflection.rb +5 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c154e7165f6bbe5e99ec3996ee46ac4062e09086c8d90e0be769106f16791df4
|
4
|
+
data.tar.gz: 1473e2ea9042d0e8405f97b53d2659c6983c95a5ac462ea9bde7858128cd3f65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2daadb48b891c1d71063a3242b9d586a72fd9f20060ae7305e53a2561ac18dc129f523d72236cfd38a37385ee9cb23331fc5029670b833f4322380436fdd368
|
7
|
+
data.tar.gz: 6f9d0d4c1729a206500141afc77a2717652fea6548d0e9b23c68b3ef96184eb57ae25bfd654f0d509d591d5faa4dc00fb4616eda5e9da86c91932894c334a946
|
data/README.md
CHANGED
@@ -34,11 +34,14 @@ module ActiveEntity::Associations::Embedded::Builder # :nodoc:
|
|
34
34
|
reflection
|
35
35
|
end
|
36
36
|
|
37
|
-
def self.create_reflection(model, name, options)
|
37
|
+
def self.create_reflection(model, name, options, &block)
|
38
38
|
raise ArgumentError, "association names must be a Symbol" unless name.kind_of?(Symbol)
|
39
39
|
|
40
40
|
validate_options(options)
|
41
41
|
|
42
|
+
extension = define_extensions(model, name, &block)
|
43
|
+
options[:extend] = [*options[:extend], extension] if extension
|
44
|
+
|
42
45
|
ActiveEntity::Reflection.create(macro, name, nil, options, model)
|
43
46
|
end
|
44
47
|
|
@@ -54,6 +57,9 @@ module ActiveEntity::Associations::Embedded::Builder # :nodoc:
|
|
54
57
|
options.assert_valid_keys(valid_options(options))
|
55
58
|
end
|
56
59
|
|
60
|
+
def self.define_extensions(model, name)
|
61
|
+
end
|
62
|
+
|
57
63
|
def self.define_callbacks(model, reflection)
|
58
64
|
Association.extensions.each do |extension|
|
59
65
|
extension.build model, reflection
|
@@ -93,8 +99,7 @@ module ActiveEntity::Associations::Embedded::Builder # :nodoc:
|
|
93
99
|
# noop
|
94
100
|
end
|
95
101
|
|
96
|
-
|
97
|
-
|
98
|
-
end
|
102
|
+
private_class_method :macro, :valid_options, :validate_options, :define_extensions,
|
103
|
+
:define_callbacks, :define_accessors, :define_readers, :define_writers, :define_validations
|
99
104
|
end
|
100
105
|
end
|
@@ -19,11 +19,11 @@ module ActiveEntity::Associations::Embedded::Builder # :nodoc:
|
|
19
19
|
}
|
20
20
|
end
|
21
21
|
|
22
|
-
def self.define_extensions(model, name)
|
22
|
+
def self.define_extensions(model, name, &block)
|
23
23
|
if block_given?
|
24
|
-
extension_module_name = "#{
|
25
|
-
extension = Module.new(&
|
26
|
-
model.
|
24
|
+
extension_module_name = "#{name.to_s.camelize}AssociationExtension"
|
25
|
+
extension = Module.new(&block)
|
26
|
+
model.const_set(extension_module_name, extension)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -65,5 +65,7 @@ module ActiveEntity::Associations::Embedded::Builder # :nodoc:
|
|
65
65
|
end
|
66
66
|
CODE
|
67
67
|
end
|
68
|
+
|
69
|
+
private_class_method :valid_options, :define_callback, :define_extensions, :define_readers, :define_writers
|
68
70
|
end
|
69
71
|
end
|
@@ -147,8 +147,18 @@ module ActiveEntity
|
|
147
147
|
|
148
148
|
def concat_records(records)
|
149
149
|
records.each do |record|
|
150
|
+
r =
|
151
|
+
if record.is_a? reflection.klass
|
152
|
+
record
|
153
|
+
elsif record.nil?
|
154
|
+
nil
|
155
|
+
elsif record.respond_to?(:to_h)
|
156
|
+
build_record(record.to_h)
|
157
|
+
end
|
158
|
+
add_to_target(r)
|
159
|
+
rescue => ex
|
150
160
|
raise_on_type_mismatch!(record)
|
151
|
-
|
161
|
+
raise ex
|
152
162
|
end
|
153
163
|
|
154
164
|
records
|
@@ -7,11 +7,17 @@ module ActiveEntity
|
|
7
7
|
class EmbedsOneAssociation < SingularAssociation #:nodoc:
|
8
8
|
private
|
9
9
|
def replace(record)
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
self.target =
|
11
|
+
if record.is_a? reflection.klass
|
12
|
+
record
|
13
|
+
elsif record.nil?
|
14
|
+
nil
|
15
|
+
elsif record.respond_to?(:to_h)
|
16
|
+
build_record(record.to_h)
|
17
|
+
end
|
18
|
+
rescue => ex
|
19
|
+
raise_on_type_mismatch!(record)
|
20
|
+
raise ex
|
15
21
|
end
|
16
22
|
end
|
17
23
|
end
|
@@ -15,8 +15,11 @@ module ActiveEntity
|
|
15
15
|
|
16
16
|
class << self
|
17
17
|
def create(macro, name, scope, options, ar_or_ae)
|
18
|
-
|
19
|
-
|
18
|
+
reflection_class_for(macro).new(name, scope, options, ar_or_ae)
|
19
|
+
|
20
|
+
# TODO: Support bridge to Active Record
|
21
|
+
# reflection = reflection_class_for(macro).new(name, scope, options, ar_or_ae)
|
22
|
+
# options[:through] ? ActiveRecord::ThroughReflection.new(reflection) : reflection
|
20
23
|
end
|
21
24
|
|
22
25
|
def add_reflection(ar_or_ae, name, reflection)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeentity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.
|
4
|
+
version: 0.0.1.beta6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jasl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|