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:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 6ff0416f9aaa7ad646b5b32ee6b488199ad877cc
         | 
| 4 | 
            +
              data.tar.gz: e65f189c879d42824993ebe70ebb28b3dcfc4856
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 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 | 
| 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 | 
            -
                  @ | 
| 31 | 
            -
             | 
| 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)
         | 
| @@ -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 | 
            -
                       | 
| 34 | 
            -
                      Controller.call(association.model,  | 
| 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 | 
            -
                       | 
| 50 | 
            +
                      data = @source.data.try(:merge, { id: id }) || id
         | 
| 51 51 |  | 
| 52 | 
            -
                      Controller.call(association.model,  | 
| 52 | 
            +
                      Controller.call(association.model, data,
         | 
| 53 53 | 
             
                        child_association_options(association))
         | 
| 54 54 | 
             
                    end
         | 
| 55 55 | 
             
                  end
         |