activerecord-transactionable 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +67 -4
- data/lib/activerecord/transactionable.rb +4 -0
- data/lib/activerecord/transactionable/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24f560d585c209ee87a623991f63e5cbea3ef511
|
4
|
+
data.tar.gz: c0faf6befe250becd30093df63419852a6de540e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43fa3813380cd66fa20d8c6745a90b364bedb55e2984e2617dcd2d830b29dc2f9319e9f9c657a11657b10e53309df627491c71c67b7ef4e3583e5ad580fd0f8f
|
7
|
+
data.tar.gz: 62fef9f3377fcf9c1b778a3f5ea40ac3a388a7c6d0c9198dc83037fef472083b342c10941127949d8dcfbf0c390ea2b82d53509e540eeeab7d9c13bf1fca8f6a
|
data/README.md
CHANGED
@@ -1,6 +1,23 @@
|
|
1
1
|
# Activerecord::Transactionable
|
2
2
|
|
3
|
-
Provides a method, `transaction_wrapper` at the class and instance levels that can be used instead of `ActiveRecord#transaction`.
|
3
|
+
Provides a method, `transaction_wrapper` at the class and instance levels that can be used instead of `ActiveRecord#transaction`. Enables you to do transactions properly, including with or without locking.
|
4
|
+
|
5
|
+
| Project | Activerecord::Transactionable |
|
6
|
+
|------------------------ | ----------------- |
|
7
|
+
| gem name | activerecord-transactionable |
|
8
|
+
| license | MIT |
|
9
|
+
| expert support | [](https://www.codementor.io/peterboling?utm_source=github&utm_medium=button&utm_term=peterboling&utm_campaign=github) |
|
10
|
+
| download rank | [](https://rubygems.org/gems/activerecord-transactionable) |
|
11
|
+
| version | [](http://badge.fury.io/rb/activerecord-transactionable) |
|
12
|
+
| dependencies | [](https://gemnasium.com/pboling/activerecord-transactionable) |
|
13
|
+
| code quality | [](https://codeclimate.com/github/pboling/activerecord-transactionable) |
|
14
|
+
| inline documenation | [](http://inch-ci.org/github/pboling/activerecord-transactionable) |
|
15
|
+
| continuous integration | [](https://travis-ci.org/pboling/activerecord-transactionable) |
|
16
|
+
| test coverage | [](https://coveralls.io/r/pboling/activerecord-transactionable) |
|
17
|
+
| homepage | [https://github.com/pboling/activerecord-transactionable][homepage] |
|
18
|
+
| documentation | [http://rdoc.info/github/pboling/activerecord-transactionable/frames][documentation] |
|
19
|
+
| live chat | [](https://gitter.im/pboling/activerecord-transactionable?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) |
|
20
|
+
| Spread ~♡ⓛⓞⓥⓔ♡~ | [on Coderbits](https://coderbits.com/pboling), [on Coderwall](http://coderwall.com/pboling) |
|
4
21
|
|
5
22
|
Useful as an example of correct behavior for wrapping transactions.
|
6
23
|
|
@@ -79,9 +96,49 @@ result # => true, false or nil
|
|
79
96
|
|
80
97
|
Meanings of `transaction_wrapper` return values:
|
81
98
|
|
82
|
-
**nil** - ActiveRecord::Rollback was raised, and then caught by the transaction, and not re-raised; the transaction failed.
|
83
|
-
**false** - An error was raised which was handled by the transaction_wrapper; the transaction failed.
|
84
|
-
**true** - The transaction was a success.
|
99
|
+
* **nil** - ActiveRecord::Rollback was raised, and then caught by the transaction, and not re-raised; the transaction failed.
|
100
|
+
* **false** - An error was raised which was handled by the transaction_wrapper; the transaction failed.
|
101
|
+
* **true** - The transaction was a success.
|
102
|
+
|
103
|
+
## Update Example
|
104
|
+
|
105
|
+
```
|
106
|
+
@client = Client.find(params[:id])
|
107
|
+
transaction_result = @client.transaction_wrapper(lock: true) do
|
108
|
+
@client.assign_attributes(client_params)
|
109
|
+
@client.save!
|
110
|
+
end
|
111
|
+
if transaction_result
|
112
|
+
render :show, locals: { client: @client }, status: :ok
|
113
|
+
else
|
114
|
+
# Something prevented update
|
115
|
+
render json: @client.errors, status: :unprocessable_entity
|
116
|
+
end
|
117
|
+
```
|
118
|
+
|
119
|
+
## Reporting to SAAS Error Tools (like Raygun, etc)
|
120
|
+
|
121
|
+
Hopefully there will be a better integration at some point, but for now, somewhere in your code do:
|
122
|
+
|
123
|
+
```
|
124
|
+
module SendToRaygun
|
125
|
+
def transaction_error_logger(**args)
|
126
|
+
super
|
127
|
+
if args[:error]
|
128
|
+
begin
|
129
|
+
Raygun.track_exception(args[:error])
|
130
|
+
Rails.logger.debug("Sent Error to Raygun: #{args[:error].class}: #{args[:error].message}")
|
131
|
+
rescue => e
|
132
|
+
Rails.logger.debug("Sending Error #{args[:error].class}: #{args[:error].message} to Raygun Failed with: #{e.class}: #{e.message}")
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
Activerecord::Transactionable::ClassMethods.class_eval do
|
139
|
+
prepend SendToRaygun
|
140
|
+
end
|
141
|
+
```
|
85
142
|
|
86
143
|
## Development
|
87
144
|
|
@@ -93,3 +150,9 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
93
150
|
|
94
151
|
Bug reports and pull requests are welcome on GitHub at https://github.com/pboling/activerecord-transactionable.
|
95
152
|
|
153
|
+
[semver]: http://semver.org/
|
154
|
+
[pvc]: http://docs.rubygems.org/read/chapter/16#page74
|
155
|
+
[railsbling]: http://www.railsbling.com
|
156
|
+
[peterboling]: http://www.peterboling.com
|
157
|
+
[documentation]: http://rdoc.info/github/pboling/activerecord-transactionable/frames
|
158
|
+
[homepage]: https://github.com/pboling/activerecord-transactionable
|
@@ -1,6 +1,10 @@
|
|
1
1
|
require "activerecord/transactionable/version"
|
2
2
|
require "active_model"
|
3
3
|
require "active_record"
|
4
|
+
# apparently needed for Rails 4.0 compatibility with rspec, when
|
5
|
+
# this gem is loaded before the rails gem by bundler, as will happen when you
|
6
|
+
# keep your Gemfile sorted alphabetically.
|
7
|
+
require "active_record/validations"
|
4
8
|
|
5
9
|
module Activerecord # Note lowercase "r" in Activerecord (different namespace than rails' module)
|
6
10
|
# SRP: Provides an example of correct behavior for wrapping transactions.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-transactionable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Boling
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -118,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
118
|
version: '0'
|
119
119
|
requirements: []
|
120
120
|
rubyforge_project:
|
121
|
-
rubygems_version: 2.
|
121
|
+
rubygems_version: 2.6.12
|
122
122
|
signing_key:
|
123
123
|
specification_version: 4
|
124
124
|
summary: Do ActiveRecord transactions the right way.
|