synced 0.0.7 → 0.0.8
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/synced/model.rb +14 -4
- data/lib/synced/synchronizer.rb +6 -2
- data/lib/synced/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: d2786ec502b4ef2aba2596f7928997723db04afa
|
4
|
+
data.tar.gz: ef2db43fbd30aa1b8be1e4705a3fbf126879b820
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74cde200cbe7d2cc2f26ff015f4be75c491c27c81599099f09bd262196c91e5cfaf941d69498ac73dd94c0e99ff534288c8ed5994608dba74e94adb936e3b2ee
|
7
|
+
data.tar.gz: e86f5074aab4550788db4454a64254e7858fe2e8ed7edce07166a42c8299284420b1cdedfd3fb4e36f6758432b4a2b9b7a7e7a829e0dd3221f334665fc3b7d8b
|
data/lib/synced/model.rb
CHANGED
@@ -20,14 +20,17 @@ module Synced
|
|
20
20
|
# object which will be mapped to local object attributes.
|
21
21
|
def synced(options = {})
|
22
22
|
class_attribute :synced_id_key, :synced_all_at_key, :synced_data_key,
|
23
|
-
:synced_local_attributes, :synced_associations, :synced_only_updated
|
23
|
+
:synced_local_attributes, :synced_associations, :synced_only_updated,
|
24
|
+
:synced_mapper_module
|
24
25
|
self.synced_id_key = options.fetch(:id_key, :synced_id)
|
25
26
|
self.synced_all_at_key = options.fetch(:synced_all_at_key,
|
26
|
-
:synced_all_at)
|
27
|
-
self.synced_data_key = options.fetch(:data_key,
|
27
|
+
synced_column_presence(:synced_all_at))
|
28
|
+
self.synced_data_key = options.fetch(:data_key,
|
29
|
+
synced_column_presence(:synced_data))
|
28
30
|
self.synced_local_attributes = options.fetch(:local_attributes, [])
|
29
31
|
self.synced_associations = options.fetch(:associations, [])
|
30
32
|
self.synced_only_updated = options.fetch(:only_updated, false)
|
33
|
+
self.synced_mapper_module = options.fetch(:mapper, nil)
|
31
34
|
include Synced::HasSyncedData
|
32
35
|
end
|
33
36
|
|
@@ -71,10 +74,17 @@ module Synced
|
|
71
74
|
associations: synced_associations,
|
72
75
|
only_updated: synced_only_updated,
|
73
76
|
include: include,
|
74
|
-
api: api
|
77
|
+
api: api,
|
78
|
+
mapper: synced_mapper_module
|
75
79
|
}
|
76
80
|
synchronizer = Synced::Synchronizer.new(remote, model_class, options)
|
77
81
|
synchronizer.perform
|
78
82
|
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
def synced_column_presence(name)
|
87
|
+
name if column_names.include?(name.to_s)
|
88
|
+
end
|
79
89
|
end
|
80
90
|
end
|
data/lib/synced/synchronizer.rb
CHANGED
@@ -35,6 +35,8 @@ module Synced
|
|
35
35
|
# @option options [Boolean] only_updated: If true requests to API will take
|
36
36
|
# advantage of updated_since param and fetch only created/changed/deleted
|
37
37
|
# remote objects
|
38
|
+
# @option options [Module] mapper: Module class which will be used for
|
39
|
+
# mapping remote objects attributes into local object attributes
|
38
40
|
def initialize(remote_objects, model_class, options = {})
|
39
41
|
@model_class = model_class
|
40
42
|
@scope = options[:scope]
|
@@ -46,6 +48,7 @@ module Synced
|
|
46
48
|
@include = options[:include]
|
47
49
|
@local_attributes = options[:local_attributes]
|
48
50
|
@api = options[:api]
|
51
|
+
@mapper = options[:mapper]
|
49
52
|
@associations = Array(options[:associations])
|
50
53
|
@remote_objects = Array(remote_objects) if remote_objects
|
51
54
|
@request_performed = false
|
@@ -56,6 +59,7 @@ module Synced
|
|
56
59
|
remove_relation.send(remove_strategy) if @remove
|
57
60
|
|
58
61
|
remote_objects.map do |remote|
|
62
|
+
remote.extend(@mapper) if @mapper
|
59
63
|
local_object = local_object_by_remote_id(remote.id) || relation_scope.new
|
60
64
|
local_object.attributes = default_attributes_mapping(remote)
|
61
65
|
local_object.attributes = local_attributes_mapping(remote)
|
@@ -81,11 +85,11 @@ module Synced
|
|
81
85
|
if @local_attributes.is_a?(Hash)
|
82
86
|
Hash[
|
83
87
|
@local_attributes.map do |k, v|
|
84
|
-
[k, v.respond_to?(:call) ? v.call(remote) : remote
|
88
|
+
[k, v.respond_to?(:call) ? v.call(remote) : remote.send(v)]
|
85
89
|
end
|
86
90
|
]
|
87
91
|
else
|
88
|
-
Hash[Array(@local_attributes).map { |k| [k, remote
|
92
|
+
Hash[Array(@local_attributes).map { |k| [k, remote.send(k)] }]
|
89
93
|
end
|
90
94
|
end
|
91
95
|
|
data/lib/synced/version.rb
CHANGED
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: 0.0.
|
4
|
+
version: 0.0.8
|
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: 2014-
|
12
|
+
date: 2014-08-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|