inclusion 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/inclusion/inclusion.rb +50 -17
- 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: fb4bf4f3c7602eaf0acc0d2cdef659f17a699aa6
|
4
|
+
data.tar.gz: 05c08fb08d78f83fad2112fb84ff22b8c6d773d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2559175cd12beaad2fa50c8e7300724f41adbc96312aa2cc4b676195c0ad9a80d81155562bd8960b6ef49323a627c76afcd5b48585b0cd4c9dd9e2156e42c031
|
7
|
+
data.tar.gz: d6923c8082bdc068691fb2f0f11d07d78297cee86b976413b9eecdbc5ea1b6b8ca8f26bb9ad853e04e7672a2b8f65e34905822a419d6a215bfa0bf377d907b62
|
data/lib/inclusion/inclusion.rb
CHANGED
@@ -1,15 +1,18 @@
|
|
1
1
|
class Inclusion
|
2
2
|
attr_reader :obj
|
3
|
-
attr_reader :
|
3
|
+
attr_reader :inclusion_names
|
4
4
|
|
5
|
-
def
|
5
|
+
def obj_const
|
6
|
+
@obj_const ||= ([Module, Class].include?(obj.class) ? obj : obj.class)
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(obj, inclusion_names)
|
6
10
|
@obj = obj
|
7
|
-
@
|
11
|
+
@inclusion_names = inclusion_names
|
8
12
|
end
|
9
13
|
|
10
|
-
def self.!(obj,
|
11
|
-
|
12
|
-
instance.!
|
14
|
+
def self.!(obj, *inclusion_names)
|
15
|
+
new(obj, inclusion_names).!
|
13
16
|
end
|
14
17
|
|
15
18
|
def !
|
@@ -17,25 +20,55 @@ class Inclusion
|
|
17
20
|
end
|
18
21
|
|
19
22
|
def extend_obj
|
20
|
-
|
23
|
+
extend(inclusion)
|
24
|
+
end
|
25
|
+
|
26
|
+
def extend(mod)
|
27
|
+
obj.extend mod if mod
|
28
|
+
mod
|
29
|
+
end
|
30
|
+
|
31
|
+
def inclusion
|
32
|
+
inclusions = inclusion_names.dup
|
21
33
|
|
22
|
-
|
23
|
-
|
34
|
+
inclusion = nil
|
35
|
+
mod = obj_const
|
36
|
+
inclusions.inject(mod) do |mod_name, inner_mod_name|
|
37
|
+
|
38
|
+
unless inclusion_defined?(mod, inner_mod_name)
|
39
|
+
break
|
40
|
+
end
|
41
|
+
|
42
|
+
inclusion = includion_mod(mod, inner_mod_name)
|
43
|
+
mod = inclusion
|
44
|
+
|
45
|
+
inner_mod_name
|
24
46
|
end
|
25
47
|
|
26
|
-
|
48
|
+
inclusion
|
27
49
|
end
|
28
50
|
|
29
|
-
def
|
30
|
-
|
31
|
-
|
51
|
+
def inclusion
|
52
|
+
mod = obj_const
|
53
|
+
|
54
|
+
inclusion_names.each do |name|
|
55
|
+
if inclusion_defined?(mod, name)
|
56
|
+
mod = includion_mod(mod, name)
|
57
|
+
next
|
58
|
+
else
|
59
|
+
mod = nil
|
60
|
+
break
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
mod
|
32
65
|
end
|
33
66
|
|
34
|
-
def
|
35
|
-
|
67
|
+
def includion_mod(mod, inner)
|
68
|
+
mod.const_get(inner, search_ancestors=false)
|
36
69
|
end
|
37
70
|
|
38
|
-
def
|
39
|
-
|
71
|
+
def inclusion_defined?(mod, inner)
|
72
|
+
mod.const_defined?(inner, search_ancestors=false)
|
40
73
|
end
|
41
74
|
end
|