synchronized_model 0.2.1 → 0.3.0

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: 8e0650e391a34a311c43ce5d5a893cca5d733159
4
- data.tar.gz: 49166070dc06eb3930132c21836c1b093d3a495f
3
+ metadata.gz: 3911727754d2946a62692b62f6eac4cba5db203b
4
+ data.tar.gz: 72ccddc961cada06f0bdc72a0221b4a37f165344
5
5
  SHA512:
6
- metadata.gz: '0581c14dd604efc3a653840b200efa747965d7f90bdcee20e4d6909836cceea03c14d6a9a2553da93ea920ed7abe0eea934d60ab10af7b43a86e45af095032a1'
7
- data.tar.gz: abb286e78958d3454a0eab030da9e77cff0b1213640538d197e9970a9cfda87ac05403e164e4684c46c7b961a237acff7563500e05bad216e06b47592c1f1552
6
+ metadata.gz: 92d8e60acbccc7fa41b6c52da80cd21ce86ce4c33ca9024f0141a27d0d51a32224a9654756aa0e53f8530d667ec272cfd12f7a99eec6d28055fbd763dbe162a4
7
+ data.tar.gz: a2eb50e4213a1baf39b2afc6d367ea21d5a0290cf710e7623eaa05f408505635910a67f910b4d747976fd0dfe1edd328a306420071b1bb23eb8bcc588ef6f3c5
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- synchronized_model (0.2.1)
4
+ synchronized_model (0.3.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -22,7 +22,14 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
25
+ ### Seeding New Apps with Table data
26
+ - Run `rake synchronized_model:publish[ClassName]`
27
+
28
+ ### Resyncing for an added column
29
+ - Run `rake synchronized_model:publish[ClassName, true]`
30
+ - It will touch each record ensuring it's updated in the receivers and not ignored
31
+ as a duplicate
32
+
26
33
 
27
34
  ## Development
28
35
 
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SynchronizedModel
4
+ class Publish
5
+ attr_reader :model
6
+
7
+ def initialize(model)
8
+ @model = model
9
+ end
10
+
11
+ def call
12
+ message = SynchronizedModel::Message.new(model).call
13
+ SynchronizedModel.publish_handler.call(message)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+ module SynchronizedModel
3
+ class Railtie < Rails::Railtie
4
+ rake_tasks do
5
+ load 'tasks/publish.rake'
6
+ end
7
+ end
8
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SynchronizedModel
4
- VERSION = '0.2.1'
4
+ VERSION = '0.3.0'
5
5
  end
@@ -1,19 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'synchronized_model/version'
4
+ require 'synchronized_model/railtie' if defined?(Rails)
4
5
 
5
6
  module SynchronizedModel
6
7
  autoload :MessageReceive, 'synchronized_model/message_receive'
7
8
  autoload :Message, 'synchronized_model/message'
8
9
  autoload :ModelMessage, 'synchronized_model/model_message'
10
+ autoload :Publish, 'synchronized_model/publish'
9
11
  autoload :PublishMixin, 'synchronized_model/publish_mixin'
10
12
  autoload :Support, 'synchronized_model/support'
11
13
 
12
14
  class << self
13
- attr_accessor :logger, :receive_resource_classes
15
+ attr_accessor :logger, :publish_handler, :receive_resource_classes
14
16
  # ```ruby
15
17
  # SynchronizedModel.configure do |config|
16
18
  # config.logger = Logger.new(STDOUT)
19
+ # config.publish_handler = proc do |message|
20
+ # Circuitry.publish("wm-otto-models", message)
21
+ # end
17
22
  # config.receive_resource_classes =
18
23
  # {
19
24
  # 'item': Item,
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+ namespace :synchronized_model do
3
+ desc 'Publish all records for a model'
4
+ task :publish,
5
+ %i(model_class_string touch_records) => :environment do |_t, args|
6
+ logger = Logger.new(STDOUT)
7
+ model_class = get_model_class(args.model_class_string)
8
+
9
+ logger.info "#{model_class.count} #{args.model_class_string} to publish"
10
+ model_class.find_each do |model|
11
+ if args.touch_records == 'true'
12
+ logger.info "Touching UUID: #{model.try(:uuid)}, ID: #{model.id}"
13
+ model.update(updated_at: Time.zone.now)
14
+ end
15
+ logger.info "Publishing UUID: #{model.try(:uuid)}, ID: #{model.id}"
16
+
17
+ SynchronizedModel::Publish.new(model).call
18
+ end
19
+ end
20
+
21
+ def get_model_class(model_class_string)
22
+ model_class = Module.const_get(model_class_string)
23
+
24
+ unless model_class.ancestors.include? ActiveRecord::Base
25
+ fail "#{model_class} is not an ActiveRecord model"
26
+ end
27
+
28
+ unless model_class.ancestors.include? SynchronizedModel::PublishMixin
29
+ fail "#{model_class} is not a publishable model"
30
+ end
31
+
32
+ model_class
33
+ end
34
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: synchronized_model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Cranston
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-06-28 00:00:00.000000000 Z
11
+ date: 2018-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -133,9 +133,12 @@ files:
133
133
  - lib/synchronized_model/message.rb
134
134
  - lib/synchronized_model/message_receive.rb
135
135
  - lib/synchronized_model/model_message.rb
136
+ - lib/synchronized_model/publish.rb
136
137
  - lib/synchronized_model/publish_mixin.rb
138
+ - lib/synchronized_model/railtie.rb
137
139
  - lib/synchronized_model/support.rb
138
140
  - lib/synchronized_model/version.rb
141
+ - lib/tasks/publish.rake
139
142
  - synchronized_model.gemspec
140
143
  homepage: https://github.com/westernmilling/synchronized_model
141
144
  licenses: