sync_machine 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +7 -0
- data/lib/rails/generators/active_record/sync_machine_generator.rb +27 -0
- data/lib/rails/generators/active_record/templates/payload.rb +10 -0
- data/lib/rails/generators/mongoid/sync_machine_generator.rb +19 -0
- data/lib/rails/generators/mongoid/templates/payload.rb +12 -0
- data/lib/rails/generators/rspec/sync_machine_generator.rb +13 -0
- data/lib/rails/generators/rspec/templates/service_spec.rb +18 -0
- data/lib/rails/generators/sync_machine_generator.rb +48 -0
- data/lib/rails/generators/templates/change_listener.rb +5 -0
- data/lib/rails/generators/templates/ensure_publication_worker.rb +22 -0
- data/lib/rails/generators/templates/find_subjects_worker.rb +5 -0
- data/lib/rails/generators/templates/sync.rb +6 -0
- data/lib/sync_machine/version.rb +1 -1
- metadata +12 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a87f8dc11ee9675808f703b22cbe674c17d1ed0e05896eb2b061c2a85062f5e9
|
4
|
+
data.tar.gz: f21649d91d260a5c4499544881e14e615d9e657e6f776ef331e408021117c600
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ed147b8be624b64816c1e9837265a05f2aa4322a82e7bfa75873199d24ab63a27ed133fbc6d3bcb51c625479a31a698b73a0eae43c1a09bfd222067c8d368b7
|
7
|
+
data.tar.gz: 4634324884852210076115e04707590a2dda67d083d968fc5c45eb793370b8ff458c442e697ebdd5f4d14b3e8a03d3eaa1d6643e5a8a8ee8cae721fdbf3febe7
|
data/.rubocop.yml
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
require "rails/generators"
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
# Generate SyncMachine files for ActiveRecord.
|
5
|
+
class SyncMachineGenerator < Rails::Generators::NamedBase
|
6
|
+
class_option :subject, type: :string
|
7
|
+
source_root File.expand_path('templates', __dir__)
|
8
|
+
|
9
|
+
def create_payload_file
|
10
|
+
template "payload.rb", "app/models/#{file_path}/payload.rb"
|
11
|
+
end
|
12
|
+
|
13
|
+
def create_payload_migration
|
14
|
+
generate(
|
15
|
+
"migration",
|
16
|
+
"create_#{singular_name}_payloads body:text generated_at:datetime subject_id:integer"
|
17
|
+
)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def subject
|
23
|
+
options['subject'] || file_name.split(/_to_/).first
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "rails/generators"
|
2
|
+
|
3
|
+
module Mongoid
|
4
|
+
# Generate SyncMachine files for Mongoid.
|
5
|
+
class SyncMachineGenerator < Rails::Generators::NamedBase
|
6
|
+
class_option :subject, type: :string
|
7
|
+
source_root File.expand_path('templates', __dir__)
|
8
|
+
|
9
|
+
def create_payload_file
|
10
|
+
template "payload.rb", "app/models/#{file_path}/payload.rb"
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def subject
|
16
|
+
options['subject'] || file_name.split(/_to_/).first
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module <%= class_name %>
|
2
|
+
class Payload
|
3
|
+
include ::Mongoid::Document
|
4
|
+
|
5
|
+
field :body, type: Hash
|
6
|
+
field :generated_at, type: Time
|
7
|
+
field :subject_id, type: String
|
8
|
+
|
9
|
+
validates :generated_at, presence: true
|
10
|
+
validates :subject_id, presence: true, uniqueness: true
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "rails/generators"
|
2
|
+
|
3
|
+
module Rspec
|
4
|
+
# Generate SyncMachine files for RSpec.
|
5
|
+
class SyncMachineGenerator < ::Rails::Generators::NamedBase
|
6
|
+
source_root File.expand_path('templates', __dir__)
|
7
|
+
|
8
|
+
def create_service_spec_file
|
9
|
+
template "service_spec.rb", "spec/services/#{file_path}_spec.rb"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rails_helper'
|
2
|
+
|
3
|
+
describe <%= class_name %> do
|
4
|
+
before do
|
5
|
+
SyncMachine.eager_load(<%= class_name %>)
|
6
|
+
clear_workers
|
7
|
+
end
|
8
|
+
|
9
|
+
def clear_workers
|
10
|
+
<%= class_name %>::FindSubjectsWorker.clear
|
11
|
+
<%= class_name %>::EnsurePublicationWorker.clear
|
12
|
+
end
|
13
|
+
|
14
|
+
def drain_workers
|
15
|
+
<%= class_name %>::FindSubjectsWorker.drain
|
16
|
+
<%= class_name %>::EnsurePublicationWorker.drain
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require "rails/generators"
|
2
|
+
|
3
|
+
# Generate SyncMachine files.
|
4
|
+
class SyncMachineGenerator < Rails::Generators::NamedBase
|
5
|
+
class_option :subject, type: :string
|
6
|
+
source_root File.expand_path('templates', __dir__)
|
7
|
+
|
8
|
+
hook_for :orm
|
9
|
+
hook_for :test_framework
|
10
|
+
|
11
|
+
def create_sync_file
|
12
|
+
template "sync.rb", "app/services/#{file_path}.rb"
|
13
|
+
end
|
14
|
+
|
15
|
+
def create_find_subjects_worker_file
|
16
|
+
template(
|
17
|
+
"find_subjects_worker.rb",
|
18
|
+
"app/workers/#{file_path}/find_subjects_worker.rb"
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_ensure_publication_worker_file
|
23
|
+
template(
|
24
|
+
"ensure_publication_worker.rb",
|
25
|
+
"app/workers/#{file_path}/ensure_publication_worker.rb"
|
26
|
+
)
|
27
|
+
end
|
28
|
+
|
29
|
+
def create_change_listener_file
|
30
|
+
template(
|
31
|
+
"change_listener.rb", "app/services/#{file_path}/change_listener.rb"
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
def append_subscribe_to_initializer
|
36
|
+
initializer_path = "config/initializers/sync_machines.rb"
|
37
|
+
create_file(initializer_path, "") unless File.exist?(initializer_path)
|
38
|
+
append_to_file(
|
39
|
+
initializer_path, "#{class_name}::ChangeListener.subscribe\n"
|
40
|
+
)
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def subject
|
46
|
+
options['subject'] || file_name.split(/_to_/).first
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module <%= class_name %>
|
2
|
+
class EnsurePublicationWorker < SyncMachine::EnsurePublicationWorker
|
3
|
+
check_publishable do |<%= subject %>|
|
4
|
+
# Return a boolean value indicating whether the <%= subject %>
|
5
|
+
# should be published at all.
|
6
|
+
end
|
7
|
+
|
8
|
+
build do |<%= subject %>|
|
9
|
+
# Generate and return a payload to send to the external service.
|
10
|
+
end
|
11
|
+
|
12
|
+
publish do |<%= subject %>, payload|
|
13
|
+
# Send the payload to the external service.
|
14
|
+
end
|
15
|
+
|
16
|
+
after_publish do |<%= subject %>|
|
17
|
+
# Execute any actions after a successful publish. This step is optional
|
18
|
+
# and can be deleted entirely.
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
data/lib/sync_machine/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sync_machine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Francis Hwang
|
@@ -214,6 +214,17 @@ files:
|
|
214
214
|
- Rakefile
|
215
215
|
- bin/console
|
216
216
|
- bin/setup
|
217
|
+
- lib/rails/generators/active_record/sync_machine_generator.rb
|
218
|
+
- lib/rails/generators/active_record/templates/payload.rb
|
219
|
+
- lib/rails/generators/mongoid/sync_machine_generator.rb
|
220
|
+
- lib/rails/generators/mongoid/templates/payload.rb
|
221
|
+
- lib/rails/generators/rspec/sync_machine_generator.rb
|
222
|
+
- lib/rails/generators/rspec/templates/service_spec.rb
|
223
|
+
- lib/rails/generators/sync_machine_generator.rb
|
224
|
+
- lib/rails/generators/templates/change_listener.rb
|
225
|
+
- lib/rails/generators/templates/ensure_publication_worker.rb
|
226
|
+
- lib/rails/generators/templates/find_subjects_worker.rb
|
227
|
+
- lib/rails/generators/templates/sync.rb
|
217
228
|
- lib/sync_machine.rb
|
218
229
|
- lib/sync_machine/change_listener.rb
|
219
230
|
- lib/sync_machine/ensure_publication.rb
|