wisper-activerecord-publisher 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 8dcbe4c060b03f1e097cb4f52c5fd42c1d560cf7
4
- data.tar.gz: 4da7867256f0fbf16ca44d2b567c6d16c5d5385a
2
+ SHA256:
3
+ metadata.gz: 164a0ca8671589cf020e6de23cc9fb349c0ef9be1ea90ebe0fbe6e8f3d4fc4c6
4
+ data.tar.gz: a0224dc694ee505e116f0a8b3d5debec80b4ca5abcb73c5aba66f7493f7a701f
5
5
  SHA512:
6
- metadata.gz: 9a691e5a2d1ad8afd807482222c03054a521f3f8252c0ac52dd3d5a94f168e34ef04c9298ec369d651f3699101a764b6aac1f2f3570ffe4e21dbad282026f23a
7
- data.tar.gz: 11fb433a6ec8e347f61621b3ca7e3ad6aebe88377b9db5e51b89c4f4f71ec3d178cee788bbf6bc1dee1220253bbb528fd21b648bf59a9bd7b5a22dccb0d78ffc
6
+ metadata.gz: f0225ec11f2609585aef571208e0ac74fe2370b1b01db4c400b39e7107bd904ce439f88398d45575c3877d7e4a5fe4157be1a7180b314d565ad1affe9cb6d25e
7
+ data.tar.gz: 27378a8026b2ca278433477c225d567be2569f76c30995a38d13642f20a828ba54c01cf2b2a75669975b819f0f8503353166520b39aee7620b71eec156e0426d
data/.gitx.yml ADDED
@@ -0,0 +1,4 @@
1
+ ---
2
+ # after releasing feature branch, auto-release gem
3
+ after_release:
4
+ - bundle exec rake release
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.1.3
data/README.md CHANGED
@@ -26,7 +26,7 @@ This gem *does* support background event processing since the events are
26
26
  published after commit and each event includes the necessary payload (ie:
27
27
  changes).
28
28
 
29
- ## Example
29
+ ### Example
30
30
 
31
31
  ```ruby
32
32
  class Foo < ActiveRecord::Base
@@ -47,6 +47,45 @@ class MyListener
47
47
  end
48
48
  ```
49
49
 
50
+ ### Limiting events per model
51
+
52
+ Rather than have a model broadcast all events, you can limit them using the `broadcast_on` method.
53
+
54
+ ```ruby
55
+ class Foo < ActiveRecord::Base
56
+ broadcast_on :create
57
+ end
58
+
59
+ class MyListener
60
+ def foo_created(model)
61
+ # do something here with the model
62
+ end
63
+
64
+ def foo_updated(model, changes)
65
+ # Will not be called
66
+ end
67
+
68
+ def foo_destroyed(model_attributes)
69
+ # Will not be called
70
+ end
71
+ end
72
+ ```
73
+
74
+ ### Changing default event broadcasts
75
+
76
+ You can turn off or limit broadcasts for all models in your application via an initializer.
77
+
78
+ ```ruby
79
+ # config/initializers/wisper_activerecord_publisher.rb
80
+
81
+ Wisper::ActiveRecord::Publisher.configure do |config|
82
+ config.default_broadcast_events = [:create, :update] # Only broadcast create and update events
83
+ end
84
+ ```
85
+
86
+ Additionally, you can disable all broadcasts in a model by calling `disable_all_lifecycle_broadcasts!` on the model
87
+ class.
88
+
50
89
  ## Development
51
90
 
52
91
  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.
data/circle.yml ADDED
@@ -0,0 +1,5 @@
1
+ ---
2
+ # skip circle ci setting up database since we use in memory
3
+ database:
4
+ override:
5
+ - echo "Using in-memory database..."
@@ -0,0 +1,27 @@
1
+ module Wisper
2
+ module ActiveRecord
3
+ module Publisher
4
+ def self.configuration
5
+ @configuration ||= Configuration.new
6
+ end
7
+
8
+ def self.configure
9
+ yield configuration
10
+ end
11
+
12
+ class Configuration
13
+ attr_reader :default_broadcast_events
14
+
15
+ def initialize
16
+ @default_broadcast_events = VALID_BROADCAST_EVENTS
17
+ end
18
+
19
+ def default_broadcast_events=(events)
20
+ raise ArgumentError, "default_broadcast_events must be an array" unless events.is_a?(Array)
21
+
22
+ @default_broadcast_events = events
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,7 +1,7 @@
1
1
  module Wisper
2
2
  module Activerecord
3
3
  module Publisher
4
- VERSION = "0.1.1"
4
+ VERSION = '0.2.0'.freeze
5
5
  end
6
6
  end
7
7
  end
@@ -1,4 +1,5 @@
1
1
  require 'wisper/activerecord/publisher/version'
2
+ require 'wisper/activerecord/publisher/configuration'
2
3
  require 'active_record'
3
4
  require 'wisper'
4
5
 
@@ -10,12 +11,31 @@ module Wisper
10
11
  module Publisher
11
12
  extend ActiveSupport::Concern
12
13
 
14
+ VALID_BROADCAST_EVENTS = %i[create update destroy].freeze
15
+
13
16
  included do
14
17
  include Wisper::Publisher
15
18
 
16
- after_commit :broadcast_create, on: :create
17
- after_commit :broadcast_update, on: :update
18
- after_commit :broadcast_destroy, on: :destroy
19
+ # NOTE: do not need to silence deprecations on Rails 5+
20
+ ActiveSupport::Deprecation.silence do
21
+ VALID_BROADCAST_EVENTS.each do |event_name|
22
+ after_commit "broadcast_#{event_name}".to_sym, on: event_name, if: -> { should_broadcast?(event_name) }
23
+ end
24
+ end
25
+
26
+ class_attribute :wisper_activerecord_publisher_broadcast_events
27
+
28
+ def self.broadcast_on(*events)
29
+ events.each do |event|
30
+ raise ArgumentError, "Unknown broadcast event '#{event}'" unless VALID_BROADCAST_EVENTS.include?(event)
31
+ end
32
+
33
+ self.wisper_activerecord_publisher_broadcast_events = events
34
+ end
35
+
36
+ def self.disable_all_lifecycle_broadcasts!
37
+ self.wisper_activerecord_publisher_broadcast_events = []
38
+ end
19
39
  end
20
40
 
21
41
  private
@@ -42,9 +62,17 @@ module Wisper
42
62
  def broadcast_event_name(lifecycle)
43
63
  "#{self.class.model_name.param_key}_#{lifecycle}"
44
64
  end
65
+
66
+ def should_broadcast?(event)
67
+ (
68
+ wisper_activerecord_publisher_broadcast_events ||
69
+ Wisper::ActiveRecord::Publisher.configuration.default_broadcast_events
70
+ ).include?(event)
71
+ end
45
72
  end
46
73
  end
47
74
  end
75
+
48
76
  ActiveSupport.on_load(:active_record) do
49
77
  include Wisper::ActiveRecord::Publisher
50
78
  end
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  spec.add_runtime_dependency 'wisper'
22
22
  spec.add_runtime_dependency 'activerecord'
23
23
 
24
- spec.add_development_dependency 'bundler', '~> 1.10'
25
- spec.add_development_dependency 'rake', '~> 10.0'
24
+ spec.add_development_dependency 'rake'
26
25
  spec.add_development_dependency 'rspec'
26
+ spec.add_development_dependency "sqlite3"
27
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wisper-activerecord-publisher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - BetterUp Developers
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-06-02 00:00:00.000000000 Z
11
+ date: 2023-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: wisper
@@ -39,35 +39,35 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: bundler
42
+ name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '1.10'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '1.10'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: rake
56
+ name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '10.0'
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '10.0'
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: rspec
70
+ name: sqlite3
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -80,7 +80,7 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
- description:
83
+ description:
84
84
  email:
85
85
  - developers@betterup.co
86
86
  executables: []
@@ -88,7 +88,9 @@ extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
90
  - ".gitignore"
91
+ - ".gitx.yml"
91
92
  - ".rspec"
93
+ - ".ruby-version"
92
94
  - ".travis.yml"
93
95
  - Gemfile
94
96
  - MIT-LICENSE
@@ -96,14 +98,16 @@ files:
96
98
  - Rakefile
97
99
  - bin/console
98
100
  - bin/setup
101
+ - circle.yml
99
102
  - lib/wisper/activerecord/publisher.rb
103
+ - lib/wisper/activerecord/publisher/configuration.rb
100
104
  - lib/wisper/activerecord/publisher/version.rb
101
105
  - wisper-activerecord-publisher.gemspec
102
106
  homepage: https://github.com/betterup/wisper-activerecord-publisher
103
107
  licenses:
104
108
  - MIT
105
109
  metadata: {}
106
- post_install_message:
110
+ post_install_message:
107
111
  rdoc_options: []
108
112
  require_paths:
109
113
  - lib
@@ -118,10 +122,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
122
  - !ruby/object:Gem::Version
119
123
  version: '0'
120
124
  requirements: []
121
- rubyforge_project:
122
- rubygems_version: 2.6.4
123
- signing_key:
125
+ rubygems_version: 3.3.26
126
+ signing_key:
124
127
  specification_version: 4
125
128
  summary: Publish wisper events for activerecord model lifecycle
126
129
  test_files: []
127
- has_rdoc: