synchronisable 1.0.5 → 1.0.6

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
  SHA1:
3
- metadata.gz: ef3f05db3248f6b97f08228ce7efb74b4e515272
4
- data.tar.gz: b973aef1b36c665a89cfcbb350863eea51034ba0
3
+ metadata.gz: 6ff0416f9aaa7ad646b5b32ee6b488199ad877cc
4
+ data.tar.gz: e65f189c879d42824993ebe70ebb28b3dcfc4856
5
5
  SHA512:
6
- metadata.gz: 4ef0a3f27605d49e471f170c889ac92a3895406765a770aa86ab907325c55077081cee6c0b12c809303dff7c2c3232ec0a90499c3e99ad8f966d58e09858c07c
7
- data.tar.gz: 3c0ef536eb6433a0f421ea4d4f1f161aac67a2898e1314e13438857edaa4b9af12e394be6c222b8be465b75ba61d213bffe89bf04f4f146d9a67901532c42ba3
6
+ metadata.gz: 581aa6d3cbbbd3de78d80bb87e809ffa172cdae973b8a52009514cc1ce1e5327ef8849e8e9ee743d68195213e81ce2e713f5308ffd5cd474b1a15de9293cf808
7
+ data.tar.gz: 7b5fc2d204e008b189d01359d52721dbdd0b476b16bd23e0a2b2ecf650ceba7ead3cb54ee08491c67620e9901ad968a4881cd7c28c55cb34c63a62b4a6994d18
@@ -53,14 +53,14 @@ module Synchronisable
53
53
  def call(data)
54
54
  sync do |context|
55
55
  error_handler = ErrorHandler.new(logger, context)
56
+ source = Source.new(@model, @parent, @includes)
57
+
56
58
  context.before = @model.imports_count
57
59
 
58
60
  hashes = @input.parse(data)
59
61
  hashes.each do |attrs|
60
- source = Source.new(@model, @parent, @includes, attrs)
61
-
62
62
  error_handler.handle(source) do
63
- source.prepare
63
+ source.prepare(data, attrs)
64
64
 
65
65
  record_worker = Worker::Record.new(@synchronizer, source)
66
66
  associations_worker = Worker::Associations.new(@synchronizer, source)
@@ -10,13 +10,12 @@ module Synchronisable
10
10
  attr_reader :parent_associations, :child_associations
11
11
  attr_reader :model, :remote_attrs, :remote_id,
12
12
  :local_attrs, :import_ids, :parent,
13
- :includes
13
+ :includes, :data
14
14
 
15
- def initialize(model, parent, includes, remote_attrs)
15
+ def initialize(model, parent, includes)
16
16
  @model, @parent, @synchronizer = model, parent, model.synchronizer
17
17
  @model_name = @model.to_s.demodulize.underscore.to_sym
18
18
  @includes = includes
19
- @remote_attrs = remote_attrs.with_indifferent_access
20
19
  end
21
20
 
22
21
  # Prepares synchronization source:
@@ -26,9 +25,15 @@ module Synchronisable
26
25
  # association of parent model.
27
26
  #
28
27
  # @api private
29
- def prepare
30
- @remote_id = @synchronizer.extract_remote_id(@remote_attrs)
31
- @local_attrs = @synchronizer.map_attributes(@remote_attrs)
28
+ def prepare(data, remote_attrs)
29
+ @data = @parent
30
+ .try(:source).try(:data)
31
+ .try(:merge, data) || data
32
+
33
+ @remote_attrs = remote_attrs.with_indifferent_access
34
+
35
+ @remote_id = @synchronizer.extract_remote_id(@remote_attrs)
36
+ @local_attrs = @synchronizer.map_attributes(@remote_attrs)
32
37
  @associations = @synchronizer.associations_for(@local_attrs)
33
38
 
34
39
  @parent_associations = filter_associations(PARENT_ASSOCIATION_KEYS)
@@ -2,7 +2,7 @@ module Synchronisable
2
2
  module VERSION
3
3
  MAJOR = 1
4
4
  MINOR = 0
5
- PATCH = 5
5
+ PATCH = 6
6
6
  SUFFIX = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, PATCH, SUFFIX].compact.join('.')
@@ -30,8 +30,8 @@ module Synchronisable
30
30
  log_info("synchronizing parent association with id: #{id}", :blue)
31
31
 
32
32
  @synchronizer.with_association_sync_callbacks(@source, id, association) do
33
- attrs = association.model.synchronizer.find(id)
34
- Controller.call(association.model, [attrs])
33
+ data = @source.data.try(:merge, { id: id }) || id
34
+ Controller.call(association.model, data, {})
35
35
 
36
36
  import_record = Import.find_by(
37
37
  :remote_id => id.to_s,
@@ -47,9 +47,9 @@ module Synchronisable
47
47
  log_info("synchronizing child association with id: #{id}", :blue)
48
48
 
49
49
  @synchronizer.with_association_sync_callbacks(@source, id, association) do
50
- attrs = association.model.synchronizer.find(id)
50
+ data = @source.data.try(:merge, { id: id }) || id
51
51
 
52
- Controller.call(association.model, [attrs],
52
+ Controller.call(association.model, data,
53
53
  child_association_options(association))
54
54
  end
55
55
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: synchronisable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vasiliy Yorkin