trx_ext 1.0.0 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +4 -4
- data/lib/trx_ext/object_ext.rb +14 -11
- data/lib/trx_ext/version.rb +2 -2
- data/trx_ext.gemspec +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a28c9749e98f72553e2ca37963009fcc8ddf841f6930cc7ad6d71ba403650b2c
|
4
|
+
data.tar.gz: c45c63fdd16cb43c12d6fa6927e2d66436cb94f7b657062e0c97e92d4671c09e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 94b03b1b7a7a003a068da0799ab8de8bf594d4503f9eb763a0f68cfec3c98f8c2a90c43cf836ee42b4b31c90b872f218781ca60068dedfd10b1eb4a520d90c50
|
7
|
+
data.tar.gz: b825acd8dc75edbfb351d02a5ce622a6d75bad5b2dc1a14a011c255b31cac6afb007ee46769272d24113dacf78cafe1882af6ce0aad94e0d6fad755d1eb434d6
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,15 @@
|
|
2
2
|
|
3
3
|
Nothing new yet
|
4
4
|
|
5
|
+
## [1.0.2] - 2022-01-27
|
6
|
+
|
7
|
+
- Add support of ActiveRecord `7.0.1`
|
8
|
+
|
9
|
+
## [1.0.1] - 2021-12-26
|
10
|
+
|
11
|
+
- Add support of ActiveRecord `6.0.4.4`, `6.1.4.4` and `7.0.0`
|
12
|
+
- Fix readme
|
13
|
+
|
5
14
|
## [1.0.0] - 2021-11-27
|
6
15
|
|
7
16
|
- Initial release
|
data/README.md
CHANGED
@@ -8,7 +8,7 @@ Currently, the implementation only works for ActiveRecord PostgreSQL adapter. Fe
|
|
8
8
|
|
9
9
|
Because the implementation of this gem is a patch for `ActiveRecord::ConnectionAdapters::PostgreSQLAdapter` - carefully test its integration into your project. For example, if your project patches ActiveRecord or if some of your gems patches ActiveRecord - there might be conflicts in the implementation which could potentially lead to the data loss.
|
10
10
|
|
11
|
-
Currently, the implementation is tested for `6.0.4.1` and `
|
11
|
+
Currently, the implementation is tested for `6.0.4.4`, `6.1.4.4` and `7.0.1` versions of ActiveRecord(see [TrxExt::SUPPORTED_AR_VERSIONS](lib/trx_ext/version.rb))
|
12
12
|
|
13
13
|
## Requirements
|
14
14
|
|
@@ -38,7 +38,7 @@ Or install it yourself as:
|
|
38
38
|
require 'trx_ext'
|
39
39
|
require 'active_record'
|
40
40
|
|
41
|
-
# Object
|
41
|
+
# Object#trx is a shorthand of ActiveRecord::Base.transaction
|
42
42
|
trx do
|
43
43
|
DummyRecord.first || DummyRecord.create
|
44
44
|
end
|
@@ -154,8 +154,8 @@ There is "On complete" feature that allows you to define callbacks(blocks of cod
|
|
154
154
|
|
155
155
|
```ruby
|
156
156
|
trx do
|
157
|
-
@posts = Post.all
|
158
|
-
@users = User.all
|
157
|
+
@posts = Post.all.load
|
158
|
+
@users = User.all.load
|
159
159
|
end
|
160
160
|
```
|
161
161
|
|
data/lib/trx_ext/object_ext.rb
CHANGED
@@ -5,29 +5,32 @@ module TrxExt
|
|
5
5
|
# Wraps specified method in an +ActiveRecord+ transaction.
|
6
6
|
#
|
7
7
|
# @example
|
8
|
-
# class
|
9
|
-
#
|
10
|
-
#
|
8
|
+
# class User < ActiveRecord::Base
|
9
|
+
# class << self
|
10
|
+
# wrap_in_trx def find_or_create(name)
|
11
|
+
# user = find_by(name: name)
|
12
|
+
# user ||= create(name: name, title: 'Default')
|
13
|
+
# user
|
14
|
+
# end
|
11
15
|
# end
|
12
16
|
# end
|
13
17
|
#
|
14
|
-
#
|
15
|
-
# order.gnosis(93)
|
18
|
+
# User.find_or_create('some name')
|
16
19
|
# # (0.6ms) BEGIN
|
17
|
-
# #
|
20
|
+
# # User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."name" = $1 LIMIT 1 [["name", 'some name']]
|
21
|
+
# # User Create (1.8 ms) INSERT INTO "users" ("name", "title") VALUES ($1, $2) RETURNING "id" [["name", "some name"], ["title", "Default"]]
|
18
22
|
# # (0.2ms) COMMIT
|
19
|
-
# # => 418
|
20
23
|
#
|
21
24
|
# @param method [Symbol] a name of the method
|
22
25
|
# @return [Symbol]
|
23
26
|
def wrap_in_trx(method)
|
24
27
|
module_to_prepend = Module.new do
|
25
28
|
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
+
def #{method}(...)
|
30
|
+
trx do
|
31
|
+
super
|
32
|
+
end
|
29
33
|
end
|
30
|
-
end
|
31
34
|
RUBY
|
32
35
|
end
|
33
36
|
prepend module_to_prepend
|
data/lib/trx_ext/version.rb
CHANGED
data/trx_ext.gemspec
CHANGED
@@ -31,7 +31,7 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
32
32
|
spec.require_paths = ["lib"]
|
33
33
|
|
34
|
-
spec.add_dependency 'activerecord', '
|
34
|
+
spec.add_dependency 'activerecord', '>= 6'
|
35
35
|
spec.add_dependency 'pg', '~> 1.2'
|
36
36
|
spec.add_development_dependency 'rspec', "~> 3.10"
|
37
37
|
spec.add_development_dependency 'timecop', "~> 0.9.4"
|
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trx_ext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Dzyzenko
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '6'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '6'
|
27
27
|
- !ruby/object:Gem::Dependency
|
@@ -143,8 +143,8 @@ licenses:
|
|
143
143
|
metadata:
|
144
144
|
allowed_push_host: https://rubygems.org
|
145
145
|
homepage_uri: https://github.com/intale/trx_ext
|
146
|
-
source_code_uri: https://github.com/intale/trx_ext/tree/v1.0.
|
147
|
-
changelog_uri: https://github.com/intale/trx_ext/blob/v1.0.
|
146
|
+
source_code_uri: https://github.com/intale/trx_ext/tree/v1.0.3
|
147
|
+
changelog_uri: https://github.com/intale/trx_ext/blob/v1.0.3/CHANGELOG.md
|
148
148
|
post_install_message:
|
149
149
|
rdoc_options: []
|
150
150
|
require_paths:
|