synchronisable 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: d472312f04fe1b5f1c9b93c9a10c8336add0affb
4
- data.tar.gz: 9466cb83ab74a066516de65962e5505e00bd29c5
3
+ metadata.gz: 46e5d5f7aa22b3aba79572bb609e1944e14e5d6d
4
+ data.tar.gz: 5858c6ad336fa0e59ef3c682d29beb8c0be80aed
5
5
  SHA512:
6
- metadata.gz: a04fcd0b63eda8d9cfd03565529ecb99517bbd4a5b23fc7e84d2814053bc75f112eade1f86eae28a2ae7cfccccdb83eef7ebd2844b088033e1f0189961171d76
7
- data.tar.gz: b73604ecaf8e88c71ab83ffaac56849dd4751ed9a84a2545daf23543db7bee05b50794cb5c4ca31ae9307e31769d8f6ad7b3ce0695401a7d6ad1fd93a87d162d
6
+ metadata.gz: e925cf5b4ecf118c8f74dfa0837fde9c9942581826d9d907d88c23b135a6633dce8f6a6ce4a745d7eaa4a18e80ed7adab9f3cb188496e537bac8fbc7fb32f634
7
+ data.tar.gz: 0d40c8a690b4e03fb8770f63e5d425be912aca8c7bacec78f0f3ec13b40ac6bcb38008a37e3cb7c93ceb4ef6b31b6f19f3dbebe858a7cc568f805e155c384ebe
@@ -12,7 +12,7 @@ module Synchronisable
12
12
 
13
13
  # @return [String] summary synchronization info.
14
14
  def summary_message
15
- I18n.t('messages.result',
15
+ msg = I18n.t('messages.result',
16
16
  :model => model,
17
17
  :parent => @parent.try(:model) || 'nil',
18
18
  :before => before,
@@ -20,6 +20,13 @@ module Synchronisable
20
20
  :deleted => deleted,
21
21
  :errors => errors.count
22
22
  )
23
+
24
+ msg << I18n.t(
25
+ 'messages.errors',
26
+ :errors => errors.join('. ')
27
+ ) if errors.present?
28
+
29
+ msg
23
30
  end
24
31
  end
25
32
  end
@@ -12,7 +12,9 @@ en:
12
12
  local record: %{local_record}
13
13
  gateway_method_missing: Method %{method} is not implemented for gateway
14
14
  messages:
15
- result: |
15
+ result: >
16
16
  parent: %{parent},
17
17
  records before: %{before}, records after: %{after},
18
18
  deleted records: %{deleted}, errors: %{errors}
19
+ errors: >
20
+ Errors: %{errors}
@@ -16,3 +16,5 @@ ru:
16
16
  Синхронизация %{model}, родительская запись: %{parent}.
17
17
  Количество записей до: %{before}, количество записей после: %{after},
18
18
  количество удаленных записей: %{deleted}, количество ошибок: %{errors}
19
+ errors: >
20
+ Ошибки: %{errors}
@@ -1,3 +1,5 @@
1
+ require 'pry-byebug'
2
+
1
3
  module Synchronisable
2
4
  # TODO: Massive refactoring needed
3
5
 
@@ -33,12 +35,12 @@ module Synchronisable
33
35
 
34
36
  @remote_id = @synchronizer.extract_remote_id(@remote_attrs)
35
37
  @local_attrs = @synchronizer.map_attributes(@remote_attrs)
38
+ @unique_id = @synchronizer.uid(@local_attrs)
36
39
  @associations = @synchronizer.associations_for(@local_attrs)
37
40
 
38
41
  @parent_associations = filter_associations(PARENT_ASSOCIATION_KEYS)
39
42
  @child_associations = filter_associations(CHILD_ASSOCIATION_KEYS)
40
43
 
41
- @unique_id = @local_attrs[@synchronizer.unique_id]
42
44
  @import_record = find_import
43
45
 
44
46
  remove_association_keys_from_local_attrs
@@ -19,7 +19,7 @@ module Synchronisable
19
19
  attribute :remote_id, default: :id
20
20
 
21
21
  # The unique id to prevent sync of duplicate records.
22
- attribute :unique_id
22
+ method :unique_id, default: -> (attrs) { nil }
23
23
 
24
24
  # Mapping configuration between local model attributes and
25
25
  # its remote counterpart (including id attribute).
@@ -123,6 +123,10 @@ module Synchronisable
123
123
  data.present? ? data : gateway_instance.try(:find, params)
124
124
  end
125
125
 
126
+ def uid(attrs)
127
+ unique_id.is_a?(Proc) ? unique_id.(attrs) : attrs[unique_id]
128
+ end
129
+
126
130
  # Extracts remote id from given attribute hash.
127
131
  #
128
132
  # @param attrs [Hash] remote attributes
@@ -2,7 +2,7 @@ module Synchronisable
2
2
  module VERSION
3
3
  MAJOR = 1
4
4
  MINOR = 1
5
- PATCH = 0
5
+ PATCH = 1
6
6
  SUFFIX = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, PATCH, SUFFIX].compact.join('.')
@@ -2,7 +2,7 @@ class TournamentSynchronizer < Synchronisable::Synchronizer
2
2
  has_many :stages
3
3
 
4
4
  remote_id :tour_id
5
- unique_id :name
5
+ unique_id { |attrs| attrs[:name] }
6
6
 
7
7
  mappings(
8
8
  :eman => :name,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: synchronisable
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
  - Vasiliy Yorkin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-30 00:00:00.000000000 Z
11
+ date: 2014-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord