handle_in_transaction 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +65 -0
- data/Rakefile +12 -0
- data/config/initializers/handle_in_transaction.rb +1 -0
- data/handle_in_transaction.gemspec +23 -0
- data/lib/handle_in_transaction.rb +10 -0
- data/lib/handle_in_transaction/version.rb +3 -0
- data/test/handle_in_translation_test.rb +34 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 383edf151d3c760d3c6f4015a198f3ec6e03fe83
|
4
|
+
data.tar.gz: d6bcd19e041ba35d6b2b2096929f06b2cb5b40b7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1e2452977f0e4da626304c8b5bef26b97fd3ff3d6aaecd2113e86037dd5166e351aea59bce9a833d390aaf92da1dc0cf2a6b787a5b5f5b587dca28dbc1d10f0b
|
7
|
+
data.tar.gz: 010f7eefd39c6b80fe4c9efd2cc8a6a5b0a6b8f5b6612beb29abca1c5e376dab97b856d7e15e59658fc9df21ac2c9db774e97615fe5bb05ed247b0076832cd45
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 James Kiesel
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# HandleInTransaction
|
2
|
+
|
3
|
+
HandleInTransaction is a simple helper method to allow your ruby methods to occur within a transaction.
|
4
|
+
|
5
|
+
```
|
6
|
+
class Pelican < ActiveRecord::Base
|
7
|
+
def squawk
|
8
|
+
# many database calls!
|
9
|
+
end
|
10
|
+
handle_in_transaction :squawk
|
11
|
+
end
|
12
|
+
```
|
13
|
+
|
14
|
+
is equivalent to writing
|
15
|
+
|
16
|
+
```
|
17
|
+
class Pelican < ActiveRecord::Base
|
18
|
+
def squawk
|
19
|
+
transaction do
|
20
|
+
# many database calls!
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
```
|
25
|
+
|
26
|
+
## Installation
|
27
|
+
|
28
|
+
Add this line to your application's Gemfile:
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
gem 'handle_in_transaction'
|
32
|
+
```
|
33
|
+
|
34
|
+
And then execute:
|
35
|
+
|
36
|
+
$ bundle
|
37
|
+
|
38
|
+
Or install it yourself as:
|
39
|
+
|
40
|
+
$ gem install handle_in_transaction
|
41
|
+
|
42
|
+
## Usage
|
43
|
+
|
44
|
+
You'll now be able to use the `handle_in_transaction` helper in your models.
|
45
|
+
|
46
|
+
```
|
47
|
+
def squawk
|
48
|
+
# many database calls!
|
49
|
+
end
|
50
|
+
handle_in_transaction :squawk
|
51
|
+
```
|
52
|
+
|
53
|
+
to explicitly call a function without a transaction:
|
54
|
+
|
55
|
+
```
|
56
|
+
self.squawk_without_transaction
|
57
|
+
```
|
58
|
+
|
59
|
+
## Contributing
|
60
|
+
|
61
|
+
1. Fork it ( https://github.com/[my-github-username]/handle_in_transaction/fork )
|
62
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
63
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
64
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
65
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ActiveSupport.on_load(:active_record) { extend HandleInTransaction }
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'handle_in_transaction/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "handle_in_transaction"
|
8
|
+
spec.version = HandleInTransaction::VERSION
|
9
|
+
spec.authors = ["James Kiesel"]
|
10
|
+
spec.email = ["james.kiesel@gmail.com"]
|
11
|
+
spec.summary = "Adds a helper to wrap model methods in transactions easily."
|
12
|
+
spec.homepage = "http://www.github.com/gdpelican/handle_in_transaction"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
21
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
22
|
+
spec.add_development_dependency "activerecord", "~> 4.0.0"
|
23
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require "handle_in_transaction/version"
|
2
|
+
|
3
|
+
module HandleInTransaction
|
4
|
+
def handle_in_transaction(method_name)
|
5
|
+
aliased, punc = method_name.to_s.sub(/([?!=])$/, ''), $1
|
6
|
+
method = instance_method(aliased)
|
7
|
+
define_method(:"#{aliased}_without_transaction#{punc}") { |*args| method.bind(self).call(*args) }
|
8
|
+
define_method(:"#{aliased}#{punc}") { |*args| transaction { byebug; method.bind(self).call(*args) } }
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'active_record'
|
3
|
+
require 'temping'
|
4
|
+
|
5
|
+
require 'minitest/autorun'
|
6
|
+
require 'minitest/pride'
|
7
|
+
ActiveRecord::Base.establish_connection adapter: :sqlite3, database: ':memory:'
|
8
|
+
|
9
|
+
require 'handle_in_transaction'
|
10
|
+
|
11
|
+
class HandleInTransactionTest < MiniTest::Spec
|
12
|
+
describe HandleInTransaction do
|
13
|
+
|
14
|
+
before do
|
15
|
+
Temping.create :test_model
|
16
|
+
TestModel.send :define_method, :say_hello do |name| "Hello, #{name}!" end
|
17
|
+
TestModel.class_eval 'extend HandleInTransaction'
|
18
|
+
TestModel.class_eval 'handle_in_transaction :say_hello'
|
19
|
+
end
|
20
|
+
|
21
|
+
it "wraps a method in a Transaction" do
|
22
|
+
TestModel.stub :transaction, "I am being transacted!" do
|
23
|
+
result = TestModel.new.send(:say_hello, "James")
|
24
|
+
assert_equal result, "I am being transacted!"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
it "can call the original method" do
|
29
|
+
result = TestModel.new.send(:say_hello_without_transaction, "James")
|
30
|
+
assert_equal result, "Hello, James!"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: handle_in_transaction
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Kiesel
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activerecord
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 4.0.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 4.0.0
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- james.kiesel@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- config/initializers/handle_in_transaction.rb
|
68
|
+
- handle_in_transaction.gemspec
|
69
|
+
- lib/handle_in_transaction.rb
|
70
|
+
- lib/handle_in_transaction/version.rb
|
71
|
+
- test/handle_in_translation_test.rb
|
72
|
+
homepage: http://www.github.com/gdpelican/handle_in_transaction
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.2.2
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: Adds a helper to wrap model methods in transactions easily.
|
96
|
+
test_files:
|
97
|
+
- test/handle_in_translation_test.rb
|