dont 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/dont.rb +20 -2
  3. data/lib/dont/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8df12a0318bc20065d835a2140936de4a303b0b1
4
- data.tar.gz: 4ce2cae8395f12d253c9de429316a1ba60daeb2b
3
+ metadata.gz: 79e390ca714c283c11ab6c6ed2df51bc9623dcfe
4
+ data.tar.gz: 0e65bfb6b8d054d1cfe0311bc951b13f2edf7996
5
5
  SHA512:
6
- metadata.gz: 24da3afc49cf4a355be86e2b716165d413164597a38650de4fdd4befb9684a608875bff42b6f9de5e44ffc46c50b18b0bacb91c5818e0fde74908551c34c25cb
7
- data.tar.gz: c2deede14c9f51997d34021a5b3885566f59a7e475e6944e14c474542e12b2ce342c43cecaf2a7a5ea9f944191a17623062b0b569d91cf71bb453630137cbe8a
6
+ metadata.gz: 5673e14de0efd99161fd5e474d1809c8312c3e9e17e2048710a94f2ba3659fd5c71b46edb6e8068692ff18ddea013f3d6fc9b4a69a3f4cfeb67fa537181cbe8b
7
+ data.tar.gz: ebd77b1c6e42494ec0988fcc4c2477468702fa66edba988645e0b168cdcb5567a1ae1ab3d037fbca21db9854b8c7ea512b5ec6e0cdbc4d471e59db30a021daed
@@ -62,10 +62,28 @@ class Dont < Module
62
62
  def initialize(key)
63
63
  handler = Dont.fetch_handler(key)
64
64
  @implementation = ->(method) {
65
- old_method = instance_method(method)
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
- old_method.bind(self).call(*args)
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
@@ -1,3 +1,3 @@
1
1
  class Dont < Module
2
- VERSION = "0.1.0".freeze
2
+ VERSION = "0.1.1".freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dont
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maarten Claes