active-record-without-callbacks 0.0.1 → 0.0.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.
- data/VERSION +1 -1
- data/active-record-without-callbacks.gemspec +1 -1
- data/lib/active-record-without-callbacks.rb +10 -3
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.2
|
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "active-record-without-callbacks"
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Kasper Johansen"]
|
@@ -1,12 +1,14 @@
|
|
1
1
|
class ActiveRecordWithoutCallbacks
|
2
|
+
TRUE_BLOCK = proc{ true }
|
3
|
+
|
2
4
|
def self.wo_callbacks(klass)
|
3
5
|
#List of various possible callbacks.
|
4
|
-
takes = [:_create_callbacks, :_find_callbacks, :_initialize_callbacks, :_destroy_callbacks, :_commit_callbacks, :_rollback_callbacks, :_save_callbacks, :_touch_callbacks, :_update_callbacks, :_validate_callbacks, :_validation_callbacks]
|
6
|
+
takes = [:_create_callbacks, :_find_callbacks, :_initialize_callbacks, :_destroy_callbacks, :_commit_callbacks, :_rollback_callbacks, :_save_callbacks, :_touch_callbacks, :_update_callbacks, :_validate_callbacks, :_validation_callbacks, ]
|
5
7
|
|
6
8
|
#Array containing previous values.
|
7
9
|
saved = []
|
8
10
|
|
9
|
-
|
11
|
+
Thread.exclusive do
|
10
12
|
takes.each do |take|
|
11
13
|
#Store previous value for restoring later.
|
12
14
|
saved << {
|
@@ -17,9 +19,12 @@ class ActiveRecordWithoutCallbacks
|
|
17
19
|
#Clear all callbacks.
|
18
20
|
klass.__send__("#{take}=", [])
|
19
21
|
|
22
|
+
#Test that callbacks really was cleared.
|
20
23
|
raise "Expected '#{take}' to be empty but it wasnt: #{klass.__send__(take)}" unless klass.__send__(take).empty?
|
21
24
|
end
|
22
25
|
|
26
|
+
klass.after_save(&TRUE_BLOCK)
|
27
|
+
|
23
28
|
begin
|
24
29
|
return yield
|
25
30
|
ensure
|
@@ -27,7 +32,9 @@ class ActiveRecordWithoutCallbacks
|
|
27
32
|
saved.each do |save|
|
28
33
|
klass.__send__("#{save[:take]}=", save[:value])
|
29
34
|
end
|
35
|
+
|
36
|
+
klass.after_save(&TRUE_BLOCK)
|
30
37
|
end
|
31
|
-
|
38
|
+
end
|
32
39
|
end
|
33
40
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active-record-without-callbacks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -111,7 +111,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
111
111
|
version: '0'
|
112
112
|
segments:
|
113
113
|
- 0
|
114
|
-
hash: -
|
114
|
+
hash: -1341027000292272561
|
115
115
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
116
|
none: false
|
117
117
|
requirements:
|