hanami-mongoid 0.1.6 → 0.1.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e796aedafd20fc68fd99b0536c2600395f9fdfaf80b4819f9786ed2d9e0dd544
4
- data.tar.gz: c20824ce02f814638961b0333a4048227b0375ae625300d880e5626d2306cc76
3
+ metadata.gz: f7050c95dddb74e5f8a9704f622f27aa0b827aacaecb5385f8cef19ae27806a2
4
+ data.tar.gz: '097622667f1803c926d03f8f938b087d1a74482009b54f006104db5f8bd53747'
5
5
  SHA512:
6
- metadata.gz: 3053b6b0a7eecf5655071a1b1d610c145066573c1e5b7273f6d299372f33d29fdb8e6cf9cdd174fe8f3ada9bf929d8b01fbd752992b4c5da9f36d1c877a89e91
7
- data.tar.gz: 8663f91d683adbe4e332f71fa77488f302fef88ab67be0923ee035037bb2e44a1ea7a83f6f82d2a18451614a90a58fa44202f4d6e441c99e39ed40eff9ceeccf
6
+ metadata.gz: 1f93f89a899fb259451ddd4c849b146eb211856a28f8782c394f5e8f0fc8e95fe8de7a94ffbd173824692ac0f8cc3b1f55f72ca8380d63a8bc895e7ad25513b3
7
+ data.tar.gz: 2c0933ad41794d210f5b8a247df279be92a638729333924c2bce9dd42eb0d1af9c5ff921082f71762f8c81c2b69aaf3a40fcc423b1f31c7463648ec9c41aad47
@@ -21,20 +21,32 @@ module Hanami
21
21
 
22
22
  ##
23
23
  # Forwards create method to accept a model instance
24
- define_method :create do |model_instance|
25
- if model_instance.is_a? self.model_klass
26
- model_instance.save(validate: false)
27
- model_instance
28
- else
29
- self.model_klass.create(model_instance)
24
+ define_method :create do |entity_instance|
25
+ unless entity_instance.is_a? self.model_klass
26
+ entity_instance = self.model_klass.new(entity_instance)
27
+ end
28
+ entity_instance.save(validate: false)
29
+ entity_instance
30
+ end
31
+
32
+ ##
33
+ # Forwards update methods to accept a model instance
34
+ %i( update_attributes update ).each do |method|
35
+ define_method :update do |entity_id, entity_attributes|
36
+ entity_instance = self.model_klass.find(entity_id)
37
+ if entity_instance.present?
38
+ entity_instance.assign_attributes(entity_attributes)
39
+ entity_instance.save(validate: false)
40
+ entity_instance
41
+ end
30
42
  end
31
43
  end
32
44
 
33
45
  ##
34
46
  # Forwards common repository methods to the model instance
35
- %i( destroy delete update_attributes update ).each do |method|
36
- define_method method do |entity_id, *args|
37
- self.model_klass.find(entity_id)&.send method, *args
47
+ %i( destroy delete ).each do |method|
48
+ define_method method do |entity_id|
49
+ self.model_klass.find(entity_id)&.send method
38
50
  end
39
51
  end
40
52
 
@@ -1,5 +1,5 @@
1
1
  module Hanami
2
2
  module Mongoid
3
- VERSION = "0.1.6"
3
+ VERSION = "0.1.7"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hanami-mongoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Francesco Ballardin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-03-27 00:00:00.000000000 Z
11
+ date: 2019-03-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mongoid