interloper 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bc047e112f6e9d65787f70a15648c199831a0fad
4
- data.tar.gz: d2b90ef44c9ed7dad1f50109f0b2a9285c904b84
3
+ metadata.gz: 9a4c42296850197574e9584a94a4d5558b51a394
4
+ data.tar.gz: 231d3a66afb42b72dbdf095dfa408d59e9962fb8
5
5
  SHA512:
6
- metadata.gz: 48abd48b4fe2fccb6950e8b09a01e9394c2ee902fc6162970214ed3b5fa2d14a367bafa92a0839b4e2231c931759b48d087926a21fd3b43859cd07f6dc940d5c
7
- data.tar.gz: a624029a8a861f5dc6287b4b74712f69ad2c11d7f43524c401293dd3ac148441ec530d7eca7e1fa824dbb1a0448e57e0e6a4ab176c24562383055a2eeb893010
6
+ metadata.gz: b0e347bac1a8c4b796a4c44e191a8d45ad5f7bffa528a3f3bf39468b3ff05b59e6d185c31c0e3ea7f35d2fb148af5b1ab180a1488a9374b4898f167c2ff719fa
7
+ data.tar.gz: 3251971fd52654301b5d809a24388d812d12959b0ef14e2b45f7479887ce42f6519e3c40effd5a1d0a5686412ddd19cdc424f719d1d4508cd9fc04900f863d0e
data/lib/interloper.rb CHANGED
@@ -26,13 +26,31 @@ module Interloper
26
26
  # @return Module the Interloper module that was prepended to the including
27
27
  # class.
28
28
  def interloper_module
29
- unless self.constants.include? interloper_const_name
29
+ unless prepended? interloper_const_name
30
30
  const_set(interloper_const_name, generate_interloper_module)
31
31
  prepend const_get(interloper_const_name)
32
32
  end
33
33
  const_get(interloper_const_name)
34
34
  end
35
35
 
36
+ # @return Boolean True if the interloper module has already been prepnded;]
37
+ # false otherwise.
38
+ def prepended?(const_name)
39
+ if self.name
40
+ # If we are not anonymous, then check for the interloper constant name
41
+ # in the list of prepended modules.
42
+ prepended_modules.include? const_name
43
+ else
44
+ # If we are an anonymous class, check for the anonymous interloper
45
+ # module name in the list of constants defined for this class.
46
+ self.constants.include? interloper_const_name
47
+ end
48
+ end
49
+
50
+ def prepended_modules
51
+ ancestors.slice(0, ancestors.find_index(self))
52
+ end
53
+
36
54
  def generate_interloper_module
37
55
  Module.new do
38
56
  class << self
@@ -1,3 +1,3 @@
1
1
  module Interloper
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: interloper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Myers