compound 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/lib/compound/host.rb +31 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33141f001b6ef9e7acc84551774860fcec67d5a7
|
4
|
+
data.tar.gz: 482d9e2556a07b9c52c72b459e1edea83e48f2e6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8d844bb989e3ce8fae996bfcec6a03ecbbe9df39ee4fc69c7ff0b8c491e0e064ffda298230930dee661bd68858daf45b791fcaebfc8854cc352914c6719c367
|
7
|
+
data.tar.gz: c224e9c8fee830e26071e5554ec7ee23e2fd42ad41c3a1f3522d0f03b28a8ae99518524d4aea9c6cff72d8a9b09ebc56936b71fd3a3d1f3817d980a739e6aa1d
|
data/README.md
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
|
2
|
+
[![Build Status](https://travis-ci.org/jemc/compound.png)](https://travis-ci.org/jemc/compound)
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/compound.png)](http://badge.fury.io/rb/compound)
|
4
|
+
|
2
5
|
Compound provides a mechanism for mixing together modules into an object
|
3
6
|
while maintaining some degree of separation to help avoid namespace collisions.
|
4
7
|
|
data/lib/compound/host.rb
CHANGED
@@ -19,7 +19,9 @@ module Compound
|
|
19
19
|
# Remove the Part associated with the given module
|
20
20
|
def uncompound mod
|
21
21
|
(@_compound_parts &&
|
22
|
-
(@_compound_parts.reject! { |part|
|
22
|
+
(@_compound_parts.reject! { |part|
|
23
|
+
part.instance_variable_get(:@_compound_component_module) == mod
|
24
|
+
} ? mod : nil))
|
23
25
|
end
|
24
26
|
|
25
27
|
# Forward an undefined method if it is in one of the Parts
|
@@ -47,9 +49,24 @@ module Compound
|
|
47
49
|
|
48
50
|
private
|
49
51
|
|
52
|
+
# A private method to enumerate over all of the compound parts,
|
53
|
+
# in order of compounding, starting with the most recently compounded
|
54
|
+
def each_part &block
|
55
|
+
@_compound_parts.each &block
|
56
|
+
end
|
57
|
+
|
58
|
+
# A private method to enumerate over all of the compound parts,
|
59
|
+
# in order of compounding, starting with the most recently compounded,
|
60
|
+
# returning both the associated module and the part for each
|
61
|
+
def each_pair &block
|
62
|
+
@_compound_parts.map { |part|
|
63
|
+
[part.instance_variable_get(:@_compound_component_module), part]
|
64
|
+
}.each &block
|
65
|
+
end
|
66
|
+
|
50
67
|
# A private method to call send on each Compound::Part that defines the
|
51
|
-
#
|
52
|
-
#
|
68
|
+
# given method, whether publically or privately. The return values are
|
69
|
+
# collected into a hash with the compounded modules as the keys.
|
53
70
|
def send_to_parts sym, *args, &block
|
54
71
|
@_compound_parts.each_with_object({}) do |part, hash|
|
55
72
|
hash[part.instance_variable_get(:@_compound_component_module)] = \
|
@@ -58,6 +75,17 @@ module Compound
|
|
58
75
|
end
|
59
76
|
end
|
60
77
|
|
78
|
+
# A private method to call send on the Compound::Part
|
79
|
+
# associated with the given module.
|
80
|
+
def send_to_part mod, sym, *args, &block
|
81
|
+
@_compound_parts.each do |part|
|
82
|
+
if part.instance_variable_get(:@_compound_component_module) == mod
|
83
|
+
return part.send sym, *args, &block
|
84
|
+
end
|
85
|
+
end
|
86
|
+
raise ArgumentError, "No Part corresponding to #{mod}"
|
87
|
+
end
|
88
|
+
|
61
89
|
end
|
62
90
|
|
63
91
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: compound
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe McIlvain
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|