standard-file 0.2.5 → 0.2.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 +4 -4
- data/lib/standard_file/sync_manager.rb +13 -3
- data/lib/standard_file/version.rb +1 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 9aedc31c0aa95bb4a0ae123be4fb2586c907698d
         | 
| 4 | 
            +
              data.tar.gz: 28ad97ff10532060e4b9ea501064c1f2d8bfaf0e
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: e88485ce13f7fe0b5c08994094b1173c336e5ca6f6cb92cd8b298fbc178befabbbf69647529b59720354bd24f437a88103d826073cfbbb397f9befe4b1a14542
         | 
| 7 | 
            +
              data.tar.gz: c00e5e286926200e5505c42a9a2e8acb5cc9e979d764c38fc23aa478b16df86ff9589f5a4184d1c7c8565a40b795f0aafaed6ba8dc440d05e46e1c1236d6db6b
         | 
| @@ -16,7 +16,7 @@ module StandardFile | |
| 16 16 | 
             
                  return @sync_fields || [:content, :enc_item_key, :content_type, :auth_hash, :deleted, :created_at]
         | 
| 17 17 | 
             
                end
         | 
| 18 18 |  | 
| 19 | 
            -
                def sync(item_hashes, options)
         | 
| 19 | 
            +
                def sync(item_hashes, options, request)
         | 
| 20 20 |  | 
| 21 21 | 
             
                  in_sync_token = options[:sync_token]
         | 
| 22 22 | 
             
                  in_cursor_token = options[:cursor_token]
         | 
| @@ -24,7 +24,7 @@ module StandardFile | |
| 24 24 |  | 
| 25 25 | 
             
                  retrieved_items, cursor_token = _sync_get(in_sync_token, in_cursor_token, limit).to_a
         | 
| 26 26 | 
             
                  last_updated = DateTime.now
         | 
| 27 | 
            -
                  saved_items, unsaved_items = _sync_save(item_hashes)
         | 
| 27 | 
            +
                  saved_items, unsaved_items = _sync_save(item_hashes, request)
         | 
| 28 28 | 
             
                  if saved_items.length > 0
         | 
| 29 29 | 
             
                    last_updated = saved_items.sort_by{|m| m.updated_at}.last.updated_at
         | 
| 30 30 | 
             
                  end
         | 
| @@ -48,6 +48,10 @@ module StandardFile | |
| 48 48 | 
             
                  # conflicts occur when you are trying to save an item for which there is a pending change already
         | 
| 49 49 | 
             
                  min_conflict_interval = 20
         | 
| 50 50 |  | 
| 51 | 
            +
                  if Rails.env.development?
         | 
| 52 | 
            +
                    min_conflict_interval = 1
         | 
| 53 | 
            +
                  end
         | 
| 54 | 
            +
             | 
| 51 55 | 
             
                  saved_ids = saved_items.map{|x| x.uuid }
         | 
| 52 56 | 
             
                  retrieved_ids = retrieved_items.map{|x| x.uuid }
         | 
| 53 57 | 
             
                  conflicts = saved_ids & retrieved_ids # & is the intersection
         | 
| @@ -66,6 +70,10 @@ module StandardFile | |
| 66 70 | 
             
                      })
         | 
| 67 71 |  | 
| 68 72 | 
             
                    end
         | 
| 73 | 
            +
             | 
| 74 | 
            +
                    # We remove the item from retrieved items whether or not it satisfies the min_conflict_interval
         | 
| 75 | 
            +
                    # This is because the 'saved' value takes precedence, since that's the current value in the database.
         | 
| 76 | 
            +
                    # So by removing it from retrieved, we are forcing the client to ignore this change.
         | 
| 69 77 | 
             
                    retrieved_items.delete(conflicted)
         | 
| 70 78 | 
             
                  end
         | 
| 71 79 | 
             
                end
         | 
| @@ -97,7 +105,7 @@ module StandardFile | |
| 97 105 | 
             
                  return date
         | 
| 98 106 | 
             
                end
         | 
| 99 107 |  | 
| 100 | 
            -
                def _sync_save(item_hashes)
         | 
| 108 | 
            +
                def _sync_save(item_hashes, request)
         | 
| 101 109 | 
             
                  if !item_hashes
         | 
| 102 110 | 
             
                    return [], []
         | 
| 103 111 | 
             
                  end
         | 
| @@ -115,10 +123,12 @@ module StandardFile | |
| 115 123 | 
             
                      next
         | 
| 116 124 | 
             
                    end
         | 
| 117 125 |  | 
| 126 | 
            +
                    item.last_user_agent = request.user_agent
         | 
| 118 127 | 
             
                    item.update(item_hash.permit(*permitted_params))
         | 
| 119 128 | 
             
                    # we want to force update the updated_at field, even if no changes were made
         | 
| 120 129 | 
             
                    # item.touch
         | 
| 121 130 |  | 
| 131 | 
            +
             | 
| 122 132 | 
             
                    if item.deleted == true
         | 
| 123 133 | 
             
                      set_deleted(item)
         | 
| 124 134 | 
             
                      item.save
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: standard-file
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0.2. | 
| 4 | 
            +
              version: 0.2.6
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Standard File
         | 
| 8 8 | 
             
            autorequire: 
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2017- | 
| 11 | 
            +
            date: 2017-11-02 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: rails
         |