power-types 0.5.0 → 0.7.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: 97911d46926a1215cd7a114d6a90f8e6716a9181f0551bed8f74b8ed8718ae84
4
+ data.tar.gz: 21ca06565fb213947fa263e1e07ebe89348641413ee9d05c566cdd09b697d994
5
5
  SHA512:
6
- metadata.gz: 8dcbe2f8d896b4f3de9431d79247ce76426528ebc206a8585f33770dab9f110ad9849f8d5a46435c6fcc3fd84493cddcdec5d6b1916ce7f238dd74d4a825f6d3
7
- data.tar.gz: 26570fe587be13f151c0ac0627b361de02977ad32c3651ee1f5f6f7135b0357c33d55fe217931cc569a81a09756b8aff0efc7ef30c0d52cb35e9039db5aef87c
6
+ metadata.gz: f4abc5333d3bdfb2a1f687c31a351894393191ce61806a31f58c54c3dcc561a65d86d8cd9cfdea85041b9d0f4bc091cd040b51fce8bdded07836046f653af460
7
+ data.tar.gz: 4e7a652ee31cca5e1fa70051f9934813300385a8fcfb96f29d2137cec4b38c9a6ab51b4e3026749923405dccff9a8c5c519c1fdcba1bed0b0843fbfa6a5b954b
data/.circleci/config.yml CHANGED
@@ -14,10 +14,10 @@ executors:
14
14
  parameters:
15
15
  ruby-version:
16
16
  description: "Ruby version"
17
- default: "2.7"
17
+ default: "3.2"
18
18
  type: string
19
19
  docker:
20
- - image: circleci/ruby:<<parameters.ruby-version>>-node
20
+ - image: cimg/ruby:<<parameters.ruby-version>>-node
21
21
  environment: *env-vars
22
22
 
23
23
  commands:
@@ -28,8 +28,8 @@ commands:
28
28
  - run:
29
29
  name: Install bundle dependencies
30
30
  command: |
31
- gem install bundler:2.2.15
32
- bundle install
31
+ gem install bundler:2.2.34
32
+ bundle _2.2.34_ install
33
33
 
34
34
  jobs:
35
35
  lint:
@@ -93,7 +93,7 @@ workflows:
93
93
  - test:
94
94
  matrix:
95
95
  parameters:
96
- ruby-version: ["2.5", "2.6", "2.7"]
96
+ ruby-version: ["2.5", "2.6", "2.7", "3.1", "3.2"]
97
97
  - deploy:
98
98
  context: org-global
99
99
  filters:
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.7
1
+ 3.2
data/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ # Changelog
2
+
3
+ ## 0.7.0
4
+
5
+ Added
6
+ - Add after_destroy_commit callback [#25](https://github.com/platanus/power-types/pull/25)
7
+ - Add Ruby 3.2 support
8
+
9
+ Fixed
10
+ - Fix presenter params decoration [#26](https://github.com/platanus/power-types/pull/26)
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 four new callbacks, `after_create_commit`, `after_update_commit`, `after_save_commit` and `after_destroy_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.
@@ -294,7 +296,7 @@ To initialize a presenter inside your controller action you should execute the `
294
296
  class UsersController < InheritedResources::Base
295
297
  def show
296
298
  presenter_params = { param1: 1, param2: 2 }
297
- @presenter = present_with(:users_show, presenter_params)
299
+ @presenter = present_with(:users_show_presenter, presenter_params)
298
300
  end
299
301
  end
300
302
  ```
@@ -315,7 +317,7 @@ You can access `presenter_params` inside the presenter as an `attr_reader`
315
317
  class UsersController < InheritedResources::Base
316
318
  def show
317
319
  presenter_params = { platanus_url: "https://platan.us" }
318
- @presenter = present_with(:users_show, presenter_params)
320
+ @presenter = present_with(:users_show_presenter, presenter_params)
319
321
  end
320
322
  end
321
323
  ```
@@ -334,7 +336,7 @@ If the presenter param has a [decorator](https://github.com/drapergem/draper), t
334
336
  class UsersController < InheritedResources::Base
335
337
  def show
336
338
  presenter_params = { user: user }
337
- @presenter = present_with(:users_show, presenter_params)
339
+ @presenter = present_with(:users_show_presenter, presenter_params)
338
340
  end
339
341
 
340
342
  private
@@ -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
@@ -20,9 +20,9 @@ module PowerTypes
20
20
  attr_reader :h
21
21
 
22
22
  def decorated_value(value)
23
- return value unless value.respond_to?(:decorate)
24
-
25
23
  value.decorate
24
+ rescue NameError
25
+ value
26
26
  end
27
27
  end
28
28
  end
@@ -1,6 +1,8 @@
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,
5
+ :destroy_commit]
4
6
  OBSERVABLE_TYPES = [:before, :after]
5
7
  end
6
8
  end
@@ -1,3 +1,3 @@
1
1
  module PowerTypes
2
- VERSION = '0.5.0'
2
+ VERSION = '0.7.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.7.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: 2023-07-03 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
@@ -180,6 +200,7 @@ files:
180
200
  - ".rspec"
181
201
  - ".rubocop.yml"
182
202
  - ".ruby-version"
203
+ - CHANGELOG.md
183
204
  - CODE_OF_CONDUCT.md
184
205
  - Gemfile
185
206
  - Guardfile
@@ -235,7 +256,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
235
256
  - !ruby/object:Gem::Version
236
257
  version: '0'
237
258
  requirements: []
238
- rubygems_version: 3.1.6
259
+ rubygems_version: 3.4.10
239
260
  signing_key:
240
261
  specification_version: 4
241
262
  summary: Power Types for Rails by Platanus