synced 0.0.2 → 0.0.3

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
  SHA1:
3
- metadata.gz: 129cd901e2a89c56c4854ebc844b1f37f57833e3
4
- data.tar.gz: c52f215a8f82e22919adfc6925db0e9fbde894f4
3
+ metadata.gz: d8fd447ac4edfd7650c0cbc27b6dd390e01709b9
4
+ data.tar.gz: e0bc89a27dacb6abd1039c0e0c86eb233d85266e
5
5
  SHA512:
6
- metadata.gz: 59b45c2d36ed714e375e2d34eabe2d57ba62453aad252a4a8c6cec61f134fc692c8692476bfa5c530334ad536a48199edbde2cf372f2ca3b746aa4ffbf1b75eb
7
- data.tar.gz: 77a485f2007ce67c0f01be365622a770b41c01f96b240212fa87985e495cb0e2fbba594ca146c38cf0199d6e7ccc86a681ee58307684064512578f3e3cb30398
6
+ metadata.gz: b037b0f4e35a473b0c0d0ea4e9cc95161f362620af9ad3a5b6aabad5590080c3b6133fcfab6fc2568144e1e1b0b0d34ae7bc4fb58ed8fd79e52768a1838d6e48
7
+ data.tar.gz: cc2c8a5fcdb35be25a7dd4ebba407f6b7be476066bd95a6b60a37d6cbb44a4b78dff786f5396638cfd17271d616e09c84f9bf8ae5b057b47f397581335492e45
data/README.md CHANGED
@@ -1,3 +1,6 @@
1
+ [![Code Climate](https://codeclimate.com/github/BookingSync/synced.png)](https://codeclimate.com/github/BookingSync/synced)
2
+ [![Build Status](https://travis-ci.org/BookingSync/synced.png?branch=master)](https://travis-ci.org/BookingSync/synced)
3
+
1
4
  # Synced
2
5
 
3
6
  Synced is a Rails Engine that helps you keep local models synchronized with
@@ -1,4 +1,4 @@
1
- require "synced/engine"
1
+ require "synced/rails"
2
2
 
3
3
  module Synced
4
4
  end
@@ -3,7 +3,7 @@ require 'hashie'
3
3
  # Provide a serialized attribute for models. This attribute is `synced_data_key`
4
4
  # which by default is `:synced_data`. This is a friendlier alternative to
5
5
  # `serialize` with respect to dirty attributes.
6
- module Synced::Engine::HasSyncedData
6
+ module Synced::HasSyncedData
7
7
  extend ActiveSupport::Concern
8
8
  class SyncedData < Hashie::Mash; end
9
9
 
@@ -1,6 +1,6 @@
1
- require "synced/engine/synchronizer"
1
+ require "synced/synchronizer"
2
2
 
3
- module Synced::Engine::Model
3
+ module Synced::Model
4
4
  # Enables synced for ActiveRecord model.
5
5
  #
6
6
  # @param options [Hash] Configuration options for synced. They are inherited
@@ -27,7 +27,7 @@ module Synced::Engine::Model
27
27
  self.synced_local_attributes = options.fetch(:local_attributes, [])
28
28
  self.synced_associations = options.fetch(:associations, [])
29
29
  self.synced_only_updated = options.fetch(:only_updated, false)
30
- include Synced::Engine::HasSyncedData
30
+ include Synced::HasSyncedData
31
31
  end
32
32
 
33
33
  # Performs synchronization of given remote objects to local database.
@@ -56,7 +56,8 @@ module Synced::Engine::Model
56
56
  #
57
57
  # Rental.synchronize(remote: remote_rentals, scope: website)
58
58
  #
59
- def synchronize(remote: nil, model_class: self, scope: nil, remove: false)
59
+ def synchronize(remote: nil, model_class: self, scope: nil, remove: false,
60
+ include: nil)
60
61
  options = {
61
62
  scope: scope,
62
63
  id_key: synced_id_key,
@@ -65,10 +66,10 @@ module Synced::Engine::Model
65
66
  remove: remove,
66
67
  local_attributes: synced_local_attributes,
67
68
  associations: synced_associations,
68
- only_updated: synced_only_updated
69
+ only_updated: synced_only_updated,
70
+ include: include
69
71
  }
70
- synchronizer = Synced::Engine::Synchronizer.new(remote, model_class,
71
- options)
72
+ synchronizer = Synced::Synchronizer.new(remote, model_class, options)
72
73
  synchronizer.perform
73
74
  end
74
75
  end
@@ -1,3 +1,6 @@
1
+ require "synced/has_synced_data"
2
+ require "synced/model"
3
+
1
4
  module Synced
2
5
  class Engine < ::Rails::Engine
3
6
  isolate_namespace Synced
@@ -6,14 +9,8 @@ module Synced
6
9
  g.test_framework :rspec
7
10
  end
8
11
 
9
- config.to_prepare do
10
- require "synced/engine/has_synced_data"
11
- end
12
-
13
12
  ActiveSupport.on_load :active_record do
14
- extend Synced::Engine::Model
13
+ extend Synced::Model
15
14
  end
16
15
  end
17
16
  end
18
-
19
- require "synced/engine/model"
@@ -1,6 +1,6 @@
1
1
  # Synchronizer class which performs actual synchronization between
2
2
  # local database and given array of remote objects
3
- class Synced::Engine::Synchronizer
3
+ class Synced::Synchronizer
4
4
  attr_reader :id_key
5
5
 
6
6
  # Initializes a new Synchronizer
@@ -40,6 +40,7 @@ class Synced::Engine::Synchronizer
40
40
  @data_key = options[:data_key]
41
41
  @remove = options[:remove]
42
42
  @only_updated = options[:only_updated]
43
+ @include = options[:include]
43
44
  @local_attributes = Array(options[:local_attributes])
44
45
  @associations = Array(options[:associations])
45
46
  @remote_objects = Array(remote_objects) if remote_objects
@@ -122,11 +123,12 @@ class Synced::Engine::Synchronizer
122
123
  end
123
124
 
124
125
  def deleted_remote_objects_ids
126
+ remote_objects unless @request_performed
125
127
  api.last_response.meta[:deleted_ids]
126
128
  end
127
129
 
128
130
  def fetch_remote_objects
129
- api.get("/#{resource_name}", api_request_options).tap do
131
+ api.paginate(resource_name, api_request_options).tap do
130
132
  @request_performed = true
131
133
  end
132
134
  end
@@ -134,7 +136,12 @@ class Synced::Engine::Synchronizer
134
136
  def api_request_options
135
137
  {}.tap do |options|
136
138
  options[:include] = @associations if @associations.present?
139
+ if @include.present?
140
+ options[:include] ||= []
141
+ options[:include] += @include
142
+ end
137
143
  options[:updated_since] = minimum_updated_at if updated_since_enabled?
144
+ options[:auto_paginate] = true
138
145
  end
139
146
  end
140
147
 
@@ -1,3 +1,3 @@
1
1
  module Synced
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: synced
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastien Grosjean
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-22 00:00:00.000000000 Z
11
+ date: 2014-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -108,6 +108,34 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: vcr
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: webmock
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
111
139
  description: Keep your BookingSync Application synced with BookingSync.
112
140
  email:
113
141
  - dev@bookingsync.com
@@ -120,10 +148,10 @@ files:
120
148
  - Rakefile
121
149
  - config/routes.rb
122
150
  - lib/synced.rb
123
- - lib/synced/engine.rb
124
- - lib/synced/engine/has_synced_data.rb
125
- - lib/synced/engine/model.rb
126
- - lib/synced/engine/synchronizer.rb
151
+ - lib/synced/has_synced_data.rb
152
+ - lib/synced/model.rb
153
+ - lib/synced/rails.rb
154
+ - lib/synced/synchronizer.rb
127
155
  - lib/synced/version.rb
128
156
  homepage: https://github.com/BookingSync/synced
129
157
  licenses: