sync_machine 0.8.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sync_machine.rb +5 -0
- data/lib/sync_machine/change_listener.rb +1 -1
- data/lib/sync_machine/ensure_publication.rb +1 -1
- data/lib/sync_machine/ensure_publication/publication_history.rb +1 -1
- data/lib/sync_machine/find_subjects_worker.rb +11 -4
- data/lib/sync_machine/orm_adapters.rb +20 -0
- data/lib/sync_machine/orm_adapters/active_record_adapter.rb +28 -0
- data/lib/sync_machine/orm_adapters/mongoid_adapter.rb +28 -0
- data/lib/sync_machine/version.rb +1 -1
- data/sync_machine.gemspec +5 -0
- metadata +75 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 590006776b984bcede930cae17327932ac2e5c2e6b0d4bfab23e3f3742d0ecfa
|
4
|
+
data.tar.gz: 7e04325fae0528ba6fe48d413827c694aed86f13d69460dfb96782f38f25bc03
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e236957b67a82d29556fa8f57c6fe00f49e0cdb0f4e9c081eb29c99a0123de65ff4aae5f3c6ca308e48eb635c957cda14ce13dc2e40e2f064f6ee17e6395fbb
|
7
|
+
data.tar.gz: d49cca0da353472f8fc561d9a612df8d63a0cd745aec41cf183bc173051719c65eaa2d63d6ab0ae63b7007169c2be6b7abce3c3fd72a3415324791d89eb55f07
|
data/lib/sync_machine.rb
CHANGED
@@ -7,6 +7,7 @@ require "sync_machine/ensure_publication/deduper"
|
|
7
7
|
require "sync_machine/ensure_publication/publication_history"
|
8
8
|
require "sync_machine/ensure_publication_worker"
|
9
9
|
require "sync_machine/find_subjects_worker"
|
10
|
+
require "sync_machine/orm_adapters"
|
10
11
|
require "sync_machine/version"
|
11
12
|
|
12
13
|
# A mini-framework for intelligently publishing complex model changes to an
|
@@ -33,6 +34,10 @@ module SyncMachine
|
|
33
34
|
child_const.name.split(/::/)[0..-2].join('::').constantize
|
34
35
|
end
|
35
36
|
|
37
|
+
def orm_adapter
|
38
|
+
SyncMachine::OrmAdapters.orm_adapter(self)
|
39
|
+
end
|
40
|
+
|
36
41
|
def subject(subject_sym, opts = {})
|
37
42
|
self.subject_sym = subject_sym
|
38
43
|
self.subject_opts = ActiveSupport::HashWithIndifferentAccess.new(opts)
|
@@ -9,6 +9,12 @@ module SyncMachine
|
|
9
9
|
|
10
10
|
class_attribute :hooks
|
11
11
|
|
12
|
+
def self.add_hook(meth, block)
|
13
|
+
sync_module = SyncMachine.sync_module(self)
|
14
|
+
hooks[meth] = Hook.new(sync_module, block)
|
15
|
+
end
|
16
|
+
private_class_method :add_hook
|
17
|
+
|
12
18
|
def self.inherited(subclass)
|
13
19
|
subclass.hooks = {}
|
14
20
|
end
|
@@ -16,9 +22,9 @@ module SyncMachine
|
|
16
22
|
def self.method_missing(meth, *args, &block)
|
17
23
|
if meth.to_s == "subject_ids_from_#{parent.subject_sym}"
|
18
24
|
block ||= ->(subject) { [subject.id.to_s] }
|
19
|
-
|
25
|
+
add_hook(meth, block)
|
20
26
|
elsif meth.to_s =~ /^subject_ids_from_.*/
|
21
|
-
|
27
|
+
add_hook(meth, block)
|
22
28
|
else
|
23
29
|
super
|
24
30
|
end
|
@@ -46,7 +52,8 @@ module SyncMachine
|
|
46
52
|
|
47
53
|
# Wrap a "subject_ids_from_*" block.
|
48
54
|
class Hook
|
49
|
-
def initialize(block)
|
55
|
+
def initialize(sync_module, block)
|
56
|
+
@sync_module = sync_module
|
50
57
|
@block = block
|
51
58
|
end
|
52
59
|
|
@@ -57,7 +64,7 @@ module SyncMachine
|
|
57
64
|
@block.call(record)
|
58
65
|
end
|
59
66
|
Array.wrap(raw_source_ids).map { |raw_source_id|
|
60
|
-
|
67
|
+
@sync_module.orm_adapter.record_id_for_job(raw_source_id)
|
61
68
|
}
|
62
69
|
end
|
63
70
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Bundler.require(:default)
|
2
|
+
|
3
|
+
require "sync_machine/orm_adapters/active_record_adapter" if Module.const_defined?(:ActiveRecord)
|
4
|
+
require "sync_machine/orm_adapters/mongoid_adapter" if Module.const_defined?(:Mongoid)
|
5
|
+
|
6
|
+
module SyncMachine
|
7
|
+
# Adapt generic SyncMachine functionality to a specific ORM.
|
8
|
+
module OrmAdapters
|
9
|
+
def self.orm_adapter(sync_module)
|
10
|
+
subject_class = sync_module.subject_class
|
11
|
+
if const_defined?(:ActiveRecordAdapter) &&
|
12
|
+
subject_class < ActiveRecord::Base
|
13
|
+
ActiveRecordAdapter
|
14
|
+
elsif const_defined?(:MongoidAdapter) &&
|
15
|
+
subject_class.included_modules.include?(Mongoid::Document)
|
16
|
+
MongoidAdapter
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
begin
|
2
|
+
require 'wisper/activerecord'
|
3
|
+
rescue LoadError
|
4
|
+
Kernel.abort(
|
5
|
+
"Please install the wisper-activerecord gem when using SyncMachine with ActiveRecord."
|
6
|
+
)
|
7
|
+
end
|
8
|
+
|
9
|
+
module SyncMachine
|
10
|
+
module OrmAdapters
|
11
|
+
# Adapt generic SyncMachine functionality to ActiveRecord.
|
12
|
+
module ActiveRecordAdapter
|
13
|
+
def self.change_listener_changed_keys(record)
|
14
|
+
record.previous_changes.keys
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.record_id_for_job(record_id)
|
18
|
+
record_id
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.sufficient_changes_to_find_subjects?(record)
|
22
|
+
change_listener_changed_keys(record).present?
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
Wisper::ActiveRecord.extend_all
|
@@ -0,0 +1,28 @@
|
|
1
|
+
begin
|
2
|
+
require 'wisper/mongoid'
|
3
|
+
rescue LoadError
|
4
|
+
Kernel.abort(
|
5
|
+
"Please install the fhwang-wisper-mongoid gem when using SyncMachine with Mongoid."
|
6
|
+
)
|
7
|
+
end
|
8
|
+
|
9
|
+
module SyncMachine
|
10
|
+
module OrmAdapters
|
11
|
+
# Adapt generic SyncMachine functionality to Mongoid.
|
12
|
+
module MongoidAdapter
|
13
|
+
def self.change_listener_changed_keys(record)
|
14
|
+
record.changes.keys
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.record_id_for_job(record_id)
|
18
|
+
record_id.to_s
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.sufficient_changes_to_find_subjects?(_record)
|
22
|
+
true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
Wisper::Mongoid.extend_all
|
data/lib/sync_machine/version.rb
CHANGED
data/sync_machine.gemspec
CHANGED
@@ -39,9 +39,14 @@ Gem::Specification.new do |spec|
|
|
39
39
|
spec.add_runtime_dependency "sidekiq"
|
40
40
|
spec.add_runtime_dependency "wisper"
|
41
41
|
|
42
|
+
spec.add_development_dependency "activerecord"
|
42
43
|
spec.add_development_dependency "bundler", "~> 2.0"
|
43
44
|
spec.add_development_dependency "factory_bot"
|
45
|
+
spec.add_development_dependency "fhwang-wisper-mongoid"
|
46
|
+
spec.add_development_dependency "mongoid"
|
44
47
|
spec.add_development_dependency "rake", "~> 10.0"
|
45
48
|
spec.add_development_dependency "rspec", "~> 3.0"
|
46
49
|
spec.add_development_dependency "rspec_junit_formatter"
|
50
|
+
spec.add_development_dependency "sqlite3"
|
51
|
+
spec.add_development_dependency "wisper-activerecord"
|
47
52
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sync_machine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Francis Hwang
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-11-
|
11
|
+
date: 2019-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activerecord
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: bundler
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +94,34 @@ dependencies:
|
|
80
94
|
- - ">="
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: fhwang-wisper-mongoid
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: mongoid
|
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'
|
83
125
|
- !ruby/object:Gem::Dependency
|
84
126
|
name: rake
|
85
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,6 +164,34 @@ dependencies:
|
|
122
164
|
- - ">="
|
123
165
|
- !ruby/object:Gem::Version
|
124
166
|
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: sqlite3
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: wisper-activerecord
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
requirements:
|
185
|
+
- - ">="
|
186
|
+
- !ruby/object:Gem::Version
|
187
|
+
version: '0'
|
188
|
+
type: :development
|
189
|
+
prerelease: false
|
190
|
+
version_requirements: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
125
195
|
description: A mini-framework for intelligently publishing complex model changes to
|
126
196
|
an external API.
|
127
197
|
email:
|
@@ -151,6 +221,9 @@ files:
|
|
151
221
|
- lib/sync_machine/ensure_publication/publication_history.rb
|
152
222
|
- lib/sync_machine/ensure_publication_worker.rb
|
153
223
|
- lib/sync_machine/find_subjects_worker.rb
|
224
|
+
- lib/sync_machine/orm_adapters.rb
|
225
|
+
- lib/sync_machine/orm_adapters/active_record_adapter.rb
|
226
|
+
- lib/sync_machine/orm_adapters/mongoid_adapter.rb
|
154
227
|
- lib/sync_machine/version.rb
|
155
228
|
- sync_machine.gemspec
|
156
229
|
homepage: https://github.com/fhwang/sync_machine
|