power-types 0.5.0 → 0.6.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: 0d925bbf270d6ba204b3e091b60f5b16a5f02e5c6a76a6cee0ce710ff148f548
4
- data.tar.gz: f494be84a510e19471380a1b3163e8ccb5b320f7c3307b272090314297a0491c
3
+ metadata.gz: 4fcacd0da843b9147e8fdee88e0bee0535754df30302cac175f251aa0f1faea7
4
+ data.tar.gz: e1c7423de402d32ae8488f33b101621158f8e7f521f5ced50f68680edc5cfd0d
5
5
  SHA512:
6
- metadata.gz: 8dcbe2f8d896b4f3de9431d79247ce76426528ebc206a8585f33770dab9f110ad9849f8d5a46435c6fcc3fd84493cddcdec5d6b1916ce7f238dd74d4a825f6d3
7
- data.tar.gz: 26570fe587be13f151c0ac0627b361de02977ad32c3651ee1f5f6f7135b0357c33d55fe217931cc569a81a09756b8aff0efc7ef30c0d52cb35e9039db5aef87c
6
+ metadata.gz: db7acee0f6224fa46ae216bae6cf5b4d3a8eb7ff5256e830044e3c9573064605ef350a1da3b72d16e2f6b79d02b78e805e41e2a08b7155da491567cddbb7e031
7
+ data.tar.gz: 908d8b3c6b592b5b0e8b0dcd0db1dd13174c7d66e8b64a20e979675c89ecbd6f3394c4f7bd0f2afe4df2db1d14905e45a139c057575eb74e1e95290e7242004c
data/README.md CHANGED
@@ -257,6 +257,8 @@ end
257
257
  ```
258
258
  Note: Triggering the event will preserve the order of the methods, so in the example `kill_villain` will be called before `bury_villains_corpse`.
259
259
 
260
+ Recently we added three new callbacks, `after_create_commit`, `after_update_commit` and `after_save_commit`. With these callbacks we want to reproduce the `after_commit` transactional callback from Active Record. For this implementation we use the gem [After Commit Everywhere](https://github.com/Envek/after_commit_everywhere) to be able to use the `after_commit` callbacks outside the Active Record models.
261
+
260
262
  ### Values
261
263
 
262
264
  This pattern doesn't have a generator.
@@ -1,5 +1,7 @@
1
1
  module PowerTypes
2
2
  class Observer
3
+ include AfterCommitEverywhere
4
+
3
5
  attr_reader :object
4
6
 
5
7
  PowerTypes::Util::OBSERVABLE_EVENTS.each do |event|
@@ -34,5 +36,21 @@ module PowerTypes
34
36
  def initialize(_object)
35
37
  @object = _object
36
38
  end
39
+
40
+ PowerTypes::Util::OBSERVABLE_TRANSACTIONAL_EVENTS.each do |event|
41
+ PowerTypes::Util::OBSERVABLE_TYPES.each do |type|
42
+ next unless type == :after
43
+
44
+ method_name = "#{type}_#{event}"
45
+ callback = method_name.gsub('_commit', '')
46
+ define_singleton_method(method_name) do |method|
47
+ send(callback) { execute_method_after_commit(method) }
48
+ end
49
+ end
50
+ end
51
+
52
+ def execute_method_after_commit(method)
53
+ after_commit { send(method) }
54
+ end
37
55
  end
38
56
  end
@@ -1,6 +1,7 @@
1
1
  module PowerTypes
2
2
  module Util
3
- OBSERVABLE_EVENTS = [:create, :update, :save, :destroy, :commit]
3
+ OBSERVABLE_EVENTS = [:create, :update, :save, :destroy]
4
+ OBSERVABLE_TRANSACTIONAL_EVENTS = [:create_commit, :update_commit, :save_commit]
4
5
  OBSERVABLE_TYPES = [:before, :after]
5
6
  end
6
7
  end
@@ -1,3 +1,3 @@
1
1
  module PowerTypes
2
- VERSION = '0.5.0'
2
+ VERSION = '0.6.0'
3
3
  end
data/lib/power_types.rb CHANGED
@@ -1,16 +1,17 @@
1
- require "active_support/all"
1
+ require 'active_support/all'
2
+ require 'after_commit_everywhere'
2
3
 
3
- require "power_types/version"
4
- require "power_types/util"
5
- require "power_types/errors"
6
- require "power_types/patterns/service"
7
- require "power_types/patterns/command"
8
- require "power_types/patterns/observer/observable"
9
- require "power_types/patterns/observer/observer"
10
- require "power_types/patterns/observer/trigger"
11
- require "power_types/patterns/presenter/base_presenter"
12
- require "power_types/patterns/presenter/presentable"
13
- require "power_types/patterns/base_util"
4
+ require 'power_types/version'
5
+ require 'power_types/util'
6
+ require 'power_types/errors'
7
+ require 'power_types/patterns/service'
8
+ require 'power_types/patterns/command'
9
+ require 'power_types/patterns/observer/observable'
10
+ require 'power_types/patterns/observer/observer'
11
+ require 'power_types/patterns/observer/trigger'
12
+ require 'power_types/patterns/presenter/base_presenter'
13
+ require 'power_types/patterns/presenter/presentable'
14
+ require 'power_types/patterns/base_util'
14
15
 
15
16
  module PowerTypes
16
17
  end
data/power-types.gemspec CHANGED
@@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency "activesupport"
22
+ spec.add_dependency "after_commit_everywhere", "~> 1.2", ">= 1.2.2"
22
23
 
23
24
  spec.add_development_dependency "bundler", "~> 2.2.15"
24
25
  spec.add_development_dependency "coveralls"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: power-types
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ignacio Baixas
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2022-08-18 00:00:00.000000000 Z
12
+ date: 2022-09-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -25,6 +25,26 @@ dependencies:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
27
  version: '0'
28
+ - !ruby/object:Gem::Dependency
29
+ name: after_commit_everywhere
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '1.2'
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: 1.2.2
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - "~>"
43
+ - !ruby/object:Gem::Version
44
+ version: '1.2'
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 1.2.2
28
48
  - !ruby/object:Gem::Dependency
29
49
  name: bundler
30
50
  requirement: !ruby/object:Gem::Requirement