dont 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/dont.rb +20 -2
- data/lib/dont/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 79e390ca714c283c11ab6c6ed2df51bc9623dcfe
|
4
|
+
data.tar.gz: 0e65bfb6b8d054d1cfe0311bc951b13f2edf7996
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5673e14de0efd99161fd5e474d1809c8312c3e9e17e2048710a94f2ba3659fd5c71b46edb6e8068692ff18ddea013f3d6fc9b4a69a3f4cfeb67fa537181cbe8b
|
7
|
+
data.tar.gz: ebd77b1c6e42494ec0988fcc4c2477468702fa66edba988645e0b168cdcb5567a1ae1ab3d037fbca21db9854b8c7ea512b5ec6e0cdbc4d471e59db30a021daed
|
data/lib/dont.rb
CHANGED
@@ -62,10 +62,28 @@ class Dont < Module
|
|
62
62
|
def initialize(key)
|
63
63
|
handler = Dont.fetch_handler(key)
|
64
64
|
@implementation = ->(method) {
|
65
|
-
|
65
|
+
# The moment `dont_use` is called in ActiveRecord is before AR defines
|
66
|
+
# the attributes in the model. So you get an error when calling
|
67
|
+
# instance_method with the regular implementation.
|
68
|
+
#
|
69
|
+
# This hack determines if it's an ActiveRecord attribute or not, and
|
70
|
+
# adapts the code.
|
71
|
+
is_ar_attribute = defined?(ActiveRecord::Base) &&
|
72
|
+
ancestors.include?(ActiveRecord::Base) &&
|
73
|
+
!method_defined?(method)
|
74
|
+
|
75
|
+
old_method = instance_method(method) unless is_ar_attribute
|
66
76
|
define_method(method) do |*args|
|
67
77
|
handler.call(self, method)
|
68
|
-
|
78
|
+
if is_ar_attribute
|
79
|
+
if method =~ /=$/
|
80
|
+
self[method] = args.first
|
81
|
+
else
|
82
|
+
self[method]
|
83
|
+
end
|
84
|
+
else
|
85
|
+
old_method.bind(self).call(*args)
|
86
|
+
end
|
69
87
|
end
|
70
88
|
}
|
71
89
|
end
|
data/lib/dont/version.rb
CHANGED