eventish 0.1.0 → 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
2
  SHA256:
3
- metadata.gz: '08c9cf6785fc35a3174bf04df8a3f46011a10f1dc465ed24903d3924c293927a'
4
- data.tar.gz: 53efbd04a12d69149c594f375b3b79da0cda0a9ed6a339e09d88ff4a9d4d830b
3
+ metadata.gz: af7a6bf91a4b7cc8af46ea2520aeef223eedcce5cedceac04b7d91cc43333936
4
+ data.tar.gz: 1ab3f8d60e00c982c3044cf0fc7bf7e53dd1435914238842724d6f2f211698ba
5
5
  SHA512:
6
- metadata.gz: 3aabb2135effcd4234379ef10beda4cb8cd2a5489b6b7318e7bc9cc84de6ef84daa5972b35496636dc3d439f7829cf2ef3ef27786c7512339a24b87404b4bce8
7
- data.tar.gz: 63197732c22986bfc7f9d647808350886b71121cc9ccd3125ba35fa3f6eb3db2cc152b36c4f0fbd347224c46b9be50381a18e595014088341879769590593535
6
+ metadata.gz: dd0f4b9d8d6ec2705bd0d6679296705b5e3838730fc3fbcaa6657490dc6c108db80886cf2399220545b0b374c904da0bd1ac19beaac3e9c7af9a3efb5c625bc9
7
+ data.tar.gz: e1eb63690fde2b62cbfc0d9c52bb1beea73e03205abffef5aa24de8097c4e935d6ee15c2ee67d19dc6acd46050ef11d8b85b11cbcbd5caa86e24f6199f7c5fe2
data/README.md CHANGED
@@ -1,12 +1,14 @@
1
1
  # Eventish
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/eventish.svg)](https://badge.fury.io/rb/eventish)
4
+ [![Specs](https://github.com/blocknotes/eventish/actions/workflows/main.yml/badge.svg)](https://github.com/blocknotes/eventish/actions/workflows/main.yml)
5
+
3
6
  Yet another opinionated events library which proposes a simple API to handle... events 🎉
4
7
 
5
8
  The main features:
6
- - composable: just require the components that you need;
7
- - with adapters: support _ActiveSupport::Notifications_;
8
- - with async events: support _ActiveJob_;
9
- - with callbacks: support _ActiveRecord_.
9
+ - _composable_: just require the components that you need;
10
+ - with _adapters_: support ActiveSupport::Notifications for pub/sub events;
11
+ - with _async events_: support ActiveJob for background execution.
10
12
 
11
13
  ## Install
12
14
 
@@ -31,7 +33,7 @@ end
31
33
  Rails.configuration.after_initialize do
32
34
  Eventish::SimpleEvent.subscribe_all # NOTE: events will be available after this point
33
35
 
34
- Eventish.adapter.publish('app_loaded') # just a test event
36
+ Eventish.publish('app_loaded') # just a test event
35
37
  end
36
38
  ```
37
39
 
@@ -95,7 +97,7 @@ module Main
95
97
  end
96
98
  ```
97
99
 
98
- Publish the event: `Eventish.adapter.publish('some_event')`
100
+ Publish the event: `Eventish.publish('some_event')`
99
101
 
100
102
  ### Async events
101
103
 
@@ -122,27 +124,6 @@ module Notifications
122
124
  end
123
125
  ```
124
126
 
125
- ### Callbacks
126
-
127
- Wrapper for callbacks. Only _ActiveRecord_ is supported for now.
128
- This is just a glue component to have callbacks with a nice syntax.
129
-
130
- ```rb
131
- # initializer setup
132
- require 'eventish/callback'
133
- ```
134
-
135
- Sample model usage:
136
-
137
- ```rb
138
- class User < ActiveRecord::Base
139
- before_validation ::Eventish::Callback
140
- after_save_commit ::Eventish::Callback
141
- end
142
- ```
143
-
144
- For events definition see Simple or Async events.
145
-
146
127
  ## Do you like it? Star it!
147
128
 
148
129
  If you use this component just star it. A developer is more motivated to improve a project when there is some interest.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Eventish # :nodoc:
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
data/lib/eventish.rb CHANGED
@@ -18,6 +18,10 @@ module Eventish
18
18
  @options ||= Struct.new(*OPTIONS).new # rubocop:disable Naming/MemoizedInstanceVariableName
19
19
  end
20
20
 
21
+ def publish(event_name, target = nil, &block)
22
+ config.adapter&.publish(event_name, target, &block)
23
+ end
24
+
21
25
  def setup
22
26
  @options ||= Struct.new(*OPTIONS).new
23
27
  yield(@options) if block_given?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eventish
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mattia Roccoberton
@@ -21,7 +21,6 @@ files:
21
21
  - lib/eventish.rb
22
22
  - lib/eventish/active_job_event.rb
23
23
  - lib/eventish/adapters/active_support.rb
24
- - lib/eventish/callback.rb
25
24
  - lib/eventish/event_api.rb
26
25
  - lib/eventish/simple_event.rb
27
26
  - lib/eventish/version.rb
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Eventish
4
- class Callback
5
- class << self
6
- def callback_event(target, &block)
7
- event = "#{Eventish.underscore(target.class.to_s)}_#{__callee__}"
8
- Eventish.adapter.publish(event, target, &block)
9
- end
10
-
11
- def callback_commit_event(target, &block)
12
- event = "#{Eventish.underscore(target.class.to_s)}_after_commit"
13
- Eventish.adapter.publish(event, target, &block)
14
- end
15
-
16
- alias_method :after_initialize, :callback_event
17
- alias_method :after_find, :callback_event
18
-
19
- alias_method :before_validation, :callback_event
20
- alias_method :after_validation, :callback_event
21
-
22
- alias_method :before_create, :callback_event
23
- alias_method :around_create, :callback_event
24
- alias_method :after_create, :callback_event
25
-
26
- alias_method :before_update, :callback_event
27
- alias_method :around_update, :callback_event
28
- alias_method :after_update, :callback_event
29
-
30
- alias_method :before_save, :callback_event
31
- alias_method :around_save, :callback_event
32
- alias_method :after_save, :callback_event
33
-
34
- alias_method :before_destroy, :callback_event
35
- alias_method :around_destroy, :callback_event
36
- alias_method :after_destroy, :callback_event
37
-
38
- alias_method :after_commit, :callback_commit_event
39
- alias_method :after_save_commit, :callback_commit_event # => after_commit
40
- alias_method :after_create_commit, :callback_commit_event # => after_commit
41
- alias_method :after_update_commit, :callback_commit_event # => after_commit
42
- alias_method :after_destroy_commit, :callback_commit_event # => after_commit
43
- alias_method :after_rollback, :callback_event
44
-
45
- alias_method :after_touch, :callback_event
46
- end
47
- end
48
- end