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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a3d43e6dccb1db0de377c261da5f86acff871334f69200c08915f519318f914f
4
- data.tar.gz: 81158ddabc97764d38ba151b18009d9f66c952577f1a3e688b43b57c29a79cdd
3
+ metadata.gz: c154e7165f6bbe5e99ec3996ee46ac4062e09086c8d90e0be769106f16791df4
4
+ data.tar.gz: 1473e2ea9042d0e8405f97b53d2659c6983c95a5ac462ea9bde7858128cd3f65
5
5
  SHA512:
6
- metadata.gz: e3e165e0fd16ae6d54426b13d793c3926ea30bede6f3073dbcd37fd9e94cb9bb4f55f589e25b6814ee3b2a7fb442073c58327e8fb24635506a4e56ff7c0a01ef
7
- data.tar.gz: 4705fd097c96a368ec65fc5dbe851bf4d2d54ee632e741ee8c5d97bfd2f5e0de152f1a4f795ceb4465b2efaa0fd792929827e6c93412c2ba982640822a720aca
6
+ metadata.gz: a2daadb48b891c1d71063a3242b9d586a72fd9f20060ae7305e53a2561ac18dc129f523d72236cfd38a37385ee9cb23331fc5029670b833f4322380436fdd368
7
+ data.tar.gz: 6f9d0d4c1729a206500141afc77a2717652fea6548d0e9b23c68b3ef96184eb57ae25bfd654f0d509d591d5faa4dc00fb4616eda5e9da86c91932894c334a946
data/README.md CHANGED
@@ -35,7 +35,8 @@ class Holiday < ActiveEntity::Base
35
35
  end
36
36
 
37
37
  class HolidaysForm < ActiveEntity::Base
38
- embeds_many :holidays, reject_if: :all_blank
38
+ embeds_many :holidays
39
+ accepts_nested_attributes_for :holidays, reject_if: :all_blank
39
40
  end
40
41
  ```
41
42
 
@@ -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
- def self.valid_dependent_options
97
- raise NotImplementedError
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 = "#{model.name.demodulize}#{name.to_s.camelize}AssociationExtension"
25
- extension = Module.new(&Proc.new)
26
- model.module_parent.const_set(extension_module_name, extension)
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
- add_to_target(record)
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
- raise_on_type_mismatch!(record) if record
11
-
12
- return target unless record
13
-
14
- self.target = record
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
@@ -10,7 +10,7 @@ module ActiveEntity
10
10
  MAJOR = 0
11
11
  MINOR = 0
12
12
  TINY = 1
13
- PRE = "beta5"
13
+ PRE = "beta6"
14
14
 
15
15
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
16
16
  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
- reflection = reflection_class_for(macro).new(name, scope, options, ar_or_ae)
19
- options[:through] ? ThroughReflection.new(reflection) : reflection
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.beta5
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-04-21 00:00:00.000000000 Z
11
+ date: 2019-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport