synced 1.1.0 → 1.1.1

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: 4220ff2ed647669303e132040f72a13835a2ea11
4
- data.tar.gz: 575e7b3ba5985f389655252f040b279ec80976fc
3
+ metadata.gz: a83a3c02371bb0151640c39b2b7c529c2b499460
4
+ data.tar.gz: 21c79d0624f4802be4927d254b1ac0ab6765d33d
5
5
  SHA512:
6
- metadata.gz: 1168823d0315ebbeff7524139d86fe17defd940d2371ff6fa634471d7033d5d28eb38cca898871e009b0fe47b5e482eb215d799a0b7bc1721046ba2eea4147b5
7
- data.tar.gz: 0f6eaf9fac8a72b73f2b001afef26521485b88fa3e3279b64dce0054b0eb33aed927379843d20de869c0daf82222b80e475a6128bd1e82199c576c7a28510202
6
+ metadata.gz: e0c6e56b085199cd488d15b91ae1d1c789195e0711c8cd60f87ec8b199b5befa37a3fbde58671d4b72e14699a69014d54496650de31d237b5da19a2b84a41383
7
+ data.tar.gz: db536ee0ff73b25bd64f1245a5c60ce0236a6f670bb1a62c1041b8fab5d3b722cd593e9ef6ae23a1c169586e0373e0e388880a824913ccacd8bc8528e2c8d89e
data/lib/synced/model.rb CHANGED
@@ -34,16 +34,19 @@ module Synced
34
34
  # Works only for partial (updated_since param) synchronizations.
35
35
  # @option options [Array|Hash] delegate_attributes: Given attributes will be defined
36
36
  # on synchronized object and delegated to synced_data Hash
37
+ # @option options [Hash] search_params: Given attributes and their values
38
+ # which will be passed to api client to perform search
37
39
  def synced(options = {})
38
40
  options.symbolize_keys!
39
41
  options.assert_valid_keys(:associations, :data_key, :fields,
40
42
  :globalized_attributes, :id_key, :include, :initial_sync_since,
41
43
  :local_attributes, :mapper, :only_updated, :remove, :synced_all_at_key,
42
- :delegate_attributes)
44
+ :delegate_attributes, :search_params)
43
45
  class_attribute :synced_id_key, :synced_all_at_key, :synced_data_key,
44
46
  :synced_local_attributes, :synced_associations, :synced_only_updated,
45
47
  :synced_mapper, :synced_remove, :synced_include, :synced_fields,
46
- :synced_globalized_attributes, :synced_initial_sync_since, :synced_delegate_attributes
48
+ :synced_globalized_attributes, :synced_initial_sync_since, :synced_delegate_attributes,
49
+ :synced_search_params
47
50
  self.synced_id_key = options.fetch(:id_key, :synced_id)
48
51
  self.synced_all_at_key = options.fetch(:synced_all_at_key,
49
52
  synced_column_presence(:synced_all_at))
@@ -62,6 +65,7 @@ module Synced
62
65
  self.synced_initial_sync_since = options.fetch(:initial_sync_since,
63
66
  nil)
64
67
  self.synced_delegate_attributes = options.fetch(:delegate_attributes, [])
68
+ self.synced_search_params = options.fetch(:search_params, {})
65
69
  include Synced::DelegateAttributes
66
70
  include Synced::HasSyncedData
67
71
  end
@@ -98,10 +102,11 @@ module Synced
98
102
  def synchronize(options = {})
99
103
  options.symbolize_keys!
100
104
  options.assert_valid_keys(:api, :fields, :include, :remote, :remove,
101
- :scope, :strategy)
105
+ :scope, :strategy, :search_params)
102
106
  options[:remove] = synced_remove unless options.has_key?(:remove)
103
107
  options[:include] = Array(synced_include) unless options.has_key?(:include)
104
108
  options[:fields] = Array(synced_fields) unless options.has_key?(:fields)
109
+ options[:search_params] = synced_search_params unless options.has_key?(:search_params)
105
110
  options.merge!({
106
111
  id_key: synced_id_key,
107
112
  synced_data_key: synced_data_key,
@@ -0,0 +1,26 @@
1
+ module Synced
2
+ module Strategies
3
+ class Check
4
+ class Result
5
+ def to_s
6
+ %Q{
7
+ #{line "synced_class", model_class}
8
+ #{line "options", options}
9
+ #{line "changed count", changed.size}
10
+ #{line "additional count", additional.size}
11
+ #{line "missing count", missing.size}
12
+ #{line "changed", changed}
13
+ #{line "additional", additional}
14
+ #{line "missing", missing}
15
+ }
16
+ end
17
+
18
+ private
19
+
20
+ def line(label, value)
21
+ "#{label}:".ljust(18) + "#{value}"
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -7,7 +7,7 @@ module Synced
7
7
 
8
8
  def initialize(model_class, options = {})
9
9
  super
10
- @result = Result.new
10
+ @result = Result.new(model_class, options)
11
11
  end
12
12
 
13
13
  # Makes a DRY run of full synchronization. It checks and collects objects which
@@ -29,7 +29,9 @@ module Synced
29
29
  local_object.attributes = globalized_attributes_mapping(remote,
30
30
  local_object.translations.translated_locales)
31
31
  end
32
- result.changed << local_object.changes if local_object.changed?
32
+ if local_object.changed?
33
+ result.changed << [{ id: local_object.id }, local_object.changes]
34
+ end
33
35
  else
34
36
  result.missing << remote
35
37
  end
@@ -37,11 +39,19 @@ module Synced
37
39
  result
38
40
  end
39
41
 
42
+ # If we check model which uses cancel instead of destroy, we skip canceled
43
+ # when searching for additional objects by searching in :visible scope
44
+ def relation_scope
45
+ default_remove_strategy == :cancel_all ? super.visible : super
46
+ end
47
+
40
48
  # Represents result of synchronization integrity check
41
49
  class Result
42
- attr_accessor :changed, :missing, :additional
50
+ attr_accessor :model_class, :options, :changed, :missing, :additional
43
51
 
44
- def initialize
52
+ def initialize(model_class = nil, options = {})
53
+ @model_class = model_class
54
+ @options = options
45
55
  @changed, @missing, @additional = [], [], []
46
56
  end
47
57
 
@@ -63,6 +63,7 @@ module Synced
63
63
  @perform_request = options[:remote].nil?
64
64
  @remote_objects = Array(options[:remote]) unless @perform_request
65
65
  @globalized_attributes = synced_attributes_as_hash(options[:globalized_attributes])
66
+ @search_params = options[:search_params]
66
67
  end
67
68
 
68
69
  def perform
@@ -147,7 +148,7 @@ module Synced
147
148
  closest = [@scope, @scope.class, @model_class].find do |object|
148
149
  object.respond_to?(:api)
149
150
  end
150
- closest.try(:api) || raise(MissingAPIClient.new(@scope, @model_class))
151
+ @api ||= closest.try(:api) || raise(MissingAPIClient.new(@scope, @model_class))
151
152
  end
152
153
 
153
154
  def local_object_by_remote_id(remote_id)
@@ -181,7 +182,18 @@ module Synced
181
182
  end
182
183
  options[:fields] = @fields if @fields.present?
183
184
  options[:auto_paginate] = true
184
- end
185
+ end.merge(search_params)
186
+ end
187
+
188
+ def search_params
189
+ Hash[@search_params.map do |param, value|
190
+ final_value = value.respond_to?(:call) ? search_param_value_for_lambda(value) : value
191
+ [param, final_value]
192
+ end]
193
+ end
194
+
195
+ def search_param_value_for_lambda(func)
196
+ func.arity == 0 ? func.call : func.call(@scope)
185
197
  end
186
198
 
187
199
  def resource_name
@@ -1,3 +1,3 @@
1
1
  module Synced
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: synced
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastien Grosjean
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-06-25 00:00:00.000000000 Z
12
+ date: 2015-07-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -151,6 +151,20 @@ dependencies:
151
151
  - - "~>"
152
152
  - !ruby/object:Gem::Version
153
153
  version: 4.0.2
154
+ - !ruby/object:Gem::Dependency
155
+ name: pry
156
+ requirement: !ruby/object:Gem::Requirement
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ version: '0'
161
+ type: :development
162
+ prerelease: false
163
+ version_requirements: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
154
168
  description: Keep your BookingSync Application synced with BookingSync.
155
169
  email:
156
170
  - dev@bookingsync.com
@@ -167,6 +181,7 @@ files:
167
181
  - lib/synced/has_synced_data.rb
168
182
  - lib/synced/model.rb
169
183
  - lib/synced/rails.rb
184
+ - lib/synced/result_presenter.rb
170
185
  - lib/synced/strategies/check.rb
171
186
  - lib/synced/strategies/full.rb
172
187
  - lib/synced/strategies/updated_since.rb