sync_machine_generator 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 210e67b77b701c460eca8f8f3a77de99ed30f7101eda68664db45e4821905db0
4
+ data.tar.gz: 64412fc93cee818119b459a6b201a03a10cb7253a935359c2e61b9687c76e125
5
+ SHA512:
6
+ metadata.gz: 5c18cd945d25328587b06d7b0b3a80af1e64b8f67a49de9f0cc3a68652a4c621aeaeb6ee315bf5777747751339d789e43a22318273dd1d7c83e32cb80115ba82
7
+ data.tar.gz: 7891881e728f874d274148c37ea85439510de9f4ad1b2bffbc5265def534cd6c9bc049faacaa0cdbe509dc2c68631a51e792455986651da4801dab3ea04789b3
data/.codeclimate.yml ADDED
@@ -0,0 +1,38 @@
1
+ version: "2" # required to adjust maintainability checks
2
+ checks:
3
+ argument-count:
4
+ config:
5
+ threshold: 4
6
+ complex-logic:
7
+ config:
8
+ threshold: 4
9
+ file-lines:
10
+ config:
11
+ threshold: 250
12
+ method-complexity:
13
+ config:
14
+ threshold: 5
15
+ method-count:
16
+ config:
17
+ threshold: 20
18
+ method-lines:
19
+ config:
20
+ threshold: 25
21
+ nested-control-flow:
22
+ config:
23
+ threshold: 4
24
+ return-statements:
25
+ config:
26
+ threshold: 4
27
+ similar-code:
28
+ config:
29
+ threshold: 150
30
+ identical-code:
31
+ config:
32
+ threshold: 75
33
+ plugins:
34
+ reek:
35
+ enabled: true
36
+ rubocop:
37
+ enabled: true
38
+
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.reek.yml ADDED
@@ -0,0 +1,12 @@
1
+ ---
2
+ detectors:
3
+ DuplicateMethodCall:
4
+ max_calls: 3
5
+ UtilityFunction:
6
+ public_methods_only: true
7
+
8
+ exclude_paths:
9
+ - spec
10
+ - lib/generators/templates
11
+ - lib/generators/mongoid/templates
12
+ - lib/generators/rspec/templates
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,53 @@
1
+ AllCops:
2
+ Exclude:
3
+ - 'lib/generators/**/templates/*.rb'
4
+
5
+ Layout/ExtraSpacing:
6
+ Enabled: false
7
+
8
+ Layout/SpaceAroundOperators:
9
+ Enabled: false
10
+
11
+ Layout/SpaceInsideHashLiteralBraces:
12
+ Enabled: false
13
+
14
+ Layout/TrailingBlankLines:
15
+ Enabled: false
16
+
17
+ Metrics/BlockLength:
18
+ Exclude:
19
+ - 'spec/**/*'
20
+ - 'sync_machine_generator.gemspec'
21
+
22
+ Metrics/LineLength:
23
+ Max: 100
24
+
25
+ # Handled by Reek
26
+ Metrics/MethodLength:
27
+ Enabled: false
28
+
29
+ Style/BlockDelimiters:
30
+ Enabled: false
31
+
32
+ Style/EmptyMethod:
33
+ Exclude:
34
+ - 'spec/**/*'
35
+
36
+ Style/PercentLiteralDelimiters:
37
+ Enabled: false
38
+
39
+ Style/RandomWithOffset:
40
+ Enabled: false
41
+
42
+ Style/StringLiterals:
43
+ Enabled: false
44
+
45
+ Style/SymbolArray:
46
+ Enabled: false
47
+
48
+ Style/SymbolProc:
49
+ Exclude:
50
+ - 'spec/**/*'
51
+
52
+ Style/UnneededPercentQ:
53
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.3
7
+ before_install: gem install bundler -v 2.0.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in sync_machine_generator.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # SyncMachineGenerator
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/sync_machine_generator`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'sync_machine_generator'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install sync_machine_generator
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/sync_machine_generator.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sync_machine_generator"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,23 @@
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
+ def create_sync_file
14
+ template "sync.rb", "app/services/#{file_path}.rb"
15
+ end
16
+
17
+ private
18
+
19
+ def subject
20
+ options['subject'] || file_name.split(/_to_/).first
21
+ end
22
+ end
23
+ 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,5 @@
1
+ module <%= class_name %>
2
+ extend SyncMachine::Mongoid
3
+
4
+ subject :<%= subject %>
5
+ 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,6 @@
1
+ module SyncMachine
2
+ module Generator
3
+ VERSION = "0.1.0".freeze
4
+ end
5
+ end
6
+
@@ -0,0 +1,44 @@
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_find_subjects_worker_file
12
+ template(
13
+ "find_subjects_worker.rb",
14
+ "app/workers/#{file_path}/find_subjects_worker.rb"
15
+ )
16
+ end
17
+
18
+ def create_ensure_publication_worker_file
19
+ template(
20
+ "ensure_publication_worker.rb",
21
+ "app/workers/#{file_path}/ensure_publication_worker.rb"
22
+ )
23
+ end
24
+
25
+ def create_change_listener_file
26
+ template(
27
+ "change_listener.rb", "app/services/#{file_path}/change_listener.rb"
28
+ )
29
+ end
30
+
31
+ def append_subscribe_to_initializer
32
+ initializer_path = "config/initializers/sync_machines.rb"
33
+ create_file(initializer_path, "") unless File.exist?(initializer_path)
34
+ append_to_file(
35
+ initializer_path, "#{class_name}::ChangeListener.subscribe\n"
36
+ )
37
+ end
38
+
39
+ private
40
+
41
+ def subject
42
+ options['subject'] || file_name.split(/_to_/).first
43
+ end
44
+ end
@@ -0,0 +1,5 @@
1
+ module <%= class_name %>
2
+ class ChangeListener < SyncMachine::ChangeListener
3
+ listen_to_models :<%= subject %>
4
+ end
5
+ 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
+
@@ -0,0 +1,7 @@
1
+ module <%= class_name %>
2
+ class FindSubjectsWorker < SyncMachine::FindSubjectsWorker
3
+ subject_ids_from_<%= subject %> do |<%= subject %>|
4
+ [<%= subject %>.id.to_s]
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,31 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "generators/sync_machine_generator/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "sync_machine_generator"
7
+ spec.version = SyncMachine::Generator::VERSION
8
+ spec.authors = ["Francis Hwang"]
9
+ spec.email = ["sera@fhwang.net"]
10
+
11
+ spec.summary = %q{Rails generator for SyncMachine.}
12
+ spec.homepage = "https://github.com/fhwang/sync_machine_generator"
13
+
14
+ spec.metadata["homepage_uri"] = spec.homepage
15
+ spec.metadata["source_code_uri"] = "https://github.com/fhwang/sync_machine_generator"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_runtime_dependency "rails"
27
+
28
+ spec.add_development_dependency "bundler", "~> 2.0"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "rspec", "~> 3.0"
31
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sync_machine_generator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Francis Hwang
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-10-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ description:
70
+ email:
71
+ - sera@fhwang.net
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".codeclimate.yml"
77
+ - ".gitignore"
78
+ - ".reek.yml"
79
+ - ".rspec"
80
+ - ".rubocop.yml"
81
+ - ".travis.yml"
82
+ - Gemfile
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - lib/generators/mongoid/sync_machine_generator.rb
88
+ - lib/generators/mongoid/templates/payload.rb
89
+ - lib/generators/mongoid/templates/sync.rb
90
+ - lib/generators/rspec/sync_machine_generator.rb
91
+ - lib/generators/rspec/templates/service_spec.rb
92
+ - lib/generators/sync_machine_generator.rb
93
+ - lib/generators/sync_machine_generator/version.rb
94
+ - lib/generators/templates/change_listener.rb
95
+ - lib/generators/templates/ensure_publication_worker.rb
96
+ - lib/generators/templates/find_subjects_worker.rb
97
+ - sync_machine_generator.gemspec
98
+ homepage: https://github.com/fhwang/sync_machine_generator
99
+ licenses: []
100
+ metadata:
101
+ homepage_uri: https://github.com/fhwang/sync_machine_generator
102
+ source_code_uri: https://github.com/fhwang/sync_machine_generator
103
+ post_install_message:
104
+ rdoc_options: []
105
+ require_paths:
106
+ - lib
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ required_rubygems_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ requirements: []
118
+ rubygems_version: 3.0.6
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: Rails generator for SyncMachine.
122
+ test_files: []