active_record_disabler 0.0.2 → 0.0.3
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/README.md +0 -5
- data/lib/active_record_disabler.rb +18 -5
- metadata +1 -1
data/README.md
CHANGED
@@ -4,15 +4,28 @@ class ActiveRecordDisabledError < StandardError; end
|
|
4
4
|
|
5
5
|
module ActiveRecord
|
6
6
|
class << self
|
7
|
+
def enabled?
|
8
|
+
@enabled
|
9
|
+
end
|
10
|
+
|
7
11
|
def enable
|
8
|
-
|
12
|
+
@enabled = true
|
9
13
|
end
|
10
14
|
|
11
|
-
def disable
|
12
|
-
|
13
|
-
|
15
|
+
def disable
|
16
|
+
@enabled = false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class Relation
|
21
|
+
alias_method :_exec_queries, :exec_queries
|
14
22
|
|
15
|
-
|
23
|
+
def exec_queries(*args)
|
24
|
+
if ActiveRecord.enabled?
|
25
|
+
_exec_queries(*args)
|
26
|
+
else
|
27
|
+
raise ActiveRecordDisabledError, "Active Record is disabled"
|
28
|
+
end
|
16
29
|
end
|
17
30
|
end
|
18
31
|
end
|