inclusion 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/inclusion/inclusion.rb +50 -17
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a9870e2b6c89c98d673437921b047f1f64062429
4
- data.tar.gz: e4b0398b983808e106cd79e7ff4885c39820c4a0
3
+ metadata.gz: fb4bf4f3c7602eaf0acc0d2cdef659f17a699aa6
4
+ data.tar.gz: 05c08fb08d78f83fad2112fb84ff22b8c6d773d9
5
5
  SHA512:
6
- metadata.gz: 9631c9499347dc3534b108d84eb7d8c0d34dd9eabfba8e3c30b52d48d5a80648a0b4715160625c08fe5c5237903285e741e614f886d076fd3084e427a47ace66
7
- data.tar.gz: 91848a49d700310a0b4c10241eb6e8d7fc10393bd06eaa2bd3612c35f4508e6626207899c4e428d1e2c8d98a5c1bdbfc3930dae0d8ffdf2e48e6d27a95acd30e
6
+ metadata.gz: 2559175cd12beaad2fa50c8e7300724f41adbc96312aa2cc4b676195c0ad9a80d81155562bd8960b6ef49323a627c76afcd5b48585b0cd4c9dd9e2156e42c031
7
+ data.tar.gz: d6923c8082bdc068691fb2f0f11d07d78297cee86b976413b9eecdbc5ea1b6b8ca8f26bb9ad853e04e7672a2b8f65e34905822a419d6a215bfa0bf377d907b62
@@ -1,15 +1,18 @@
1
1
  class Inclusion
2
2
  attr_reader :obj
3
- attr_reader :inclusion_name
3
+ attr_reader :inclusion_names
4
4
 
5
- def initialize(obj, inclusion_name)
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
- @inclusion_name = inclusion_name
11
+ @inclusion_names = inclusion_names
8
12
  end
9
13
 
10
- def self.!(obj, inclusion_name)
11
- instance = new obj, inclusion_name
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
- extension = self.extension
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
- if extension.nil?
23
- return obj
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
- obj.extend extension
48
+ inclusion
27
49
  end
28
50
 
29
- def extension
30
- return nil unless defined
31
- obj_const.const_get(inclusion_name, search_ancestors=false)
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 defined
35
- obj_const.const_defined?(inclusion_name, search_ancestors=false)
67
+ def includion_mod(mod, inner)
68
+ mod.const_get(inner, search_ancestors=false)
36
69
  end
37
70
 
38
- def obj_const
39
- ([Module, Class].include?(obj.class) ? obj : obj.class)
71
+ def inclusion_defined?(mod, inner)
72
+ mod.const_defined?(inner, search_ancestors=false)
40
73
  end
41
74
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inclusion
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Sans Collective