much-mixin 0.0.1 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -6
- data/lib/much-mixin.rb +27 -31
- data/lib/much-mixin/version.rb +1 -1
- data/test/system/much-mixin_tests.rb +3 -3
- data/test/unit/much-mixin_tests.rb +3 -3
- metadata +2 -5
- data/lib/much-plugin.rb +0 -3
- data/test/system/much-plugin_tests.rb +0 -56
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 622a26403cc037812349be1ac6393a9b267edabab50137fb0fa22822a22bbd74
|
4
|
+
data.tar.gz: e4f1741bf4d76cbf19801e28c444b13d1d105c1904f6ceb25521f9661e9551bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f60941f782d2429172804bbbbd019f4e5861826c1e35f98fc57891b00c692fc6fa2253d6770c271fd96797f69d7b0515a1c5f20e9471ee0bb7cdaf583ee9850b
|
7
|
+
data.tar.gz: 9d28a55999e7bff176243d45cbd5a087864d82449841793a152df65d17ac9b02deee595549575c565afab36fcd19d668d3c4c6e408241a2d9a504d973cceb5ba
|
data/README.md
CHANGED
@@ -19,13 +19,13 @@ module MyMuchMixin
|
|
19
19
|
end
|
20
20
|
```
|
21
21
|
|
22
|
-
Mix `MuchMixin` in on
|
22
|
+
Mix `MuchMixin` in on mix-ins. Define included hooks using `mixin_included` that will be class eval'd in the scope of the receiver.
|
23
23
|
|
24
|
-
This allows you to define multiple hooks separately and ensures each hook will only be executed once - even if your
|
24
|
+
This allows you to define multiple hooks separately and ensures each hook will only be executed once - even if your mix-in is mixed-in multiple times on the same receiver.
|
25
25
|
|
26
26
|
### `mixin_class_methods` / `mixin_instance_methods`
|
27
27
|
|
28
|
-
MuchMixin provides convenience methods for defining instance/class methods on
|
28
|
+
MuchMixin provides convenience methods for defining instance/class methods on receivers:
|
29
29
|
|
30
30
|
```ruby
|
31
31
|
requre "much-mixin"
|
@@ -47,7 +47,7 @@ end
|
|
47
47
|
|
48
48
|
### `after_mixin_included`
|
49
49
|
|
50
|
-
These hooks work just like the `mixin_included` hooks, except they are evaluated _after_ any
|
50
|
+
These hooks work just like the `mixin_included` hooks, except they are evaluated _after_ any mix-in class/instance methods have been evaluated. E.g. use this to call a class method that the mix-in defines.
|
51
51
|
|
52
52
|
```ruby
|
53
53
|
requre "much-mixin"
|
@@ -56,11 +56,11 @@ module MyMuchMixin
|
|
56
56
|
include MuchMixin
|
57
57
|
|
58
58
|
after_mixin_included do
|
59
|
-
|
59
|
+
configure_the_mixin
|
60
60
|
end
|
61
61
|
|
62
62
|
mixin_class_methods do
|
63
|
-
def
|
63
|
+
def configure_the_mixin
|
64
64
|
# ...
|
65
65
|
end
|
66
66
|
end
|
data/lib/much-mixin.rb
CHANGED
@@ -8,37 +8,37 @@ module MuchMixin
|
|
8
8
|
end
|
9
9
|
|
10
10
|
module ClassMethods
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
def included(
|
15
|
-
return if
|
16
|
-
|
11
|
+
# Install an included block that first checks if the mix-in has already been
|
12
|
+
# included. If it has not been, include the receiver mixin and run all of
|
13
|
+
# the `mixin_included` blocks.
|
14
|
+
def included(mixin_receiver)
|
15
|
+
return if mixin_receiver.include?(self.much_mixin_included_detector)
|
16
|
+
mixin_receiver.send(:include, self.much_mixin_included_detector)
|
17
17
|
|
18
18
|
self.much_mixin_included_blocks.each do |block|
|
19
|
-
|
19
|
+
mixin_receiver.class_eval(&block)
|
20
20
|
end
|
21
21
|
|
22
|
-
self.
|
22
|
+
self.much_mixin_class_method_blocks.each do |block|
|
23
23
|
self.much_mixin_class_methods_module.class_eval(&block)
|
24
24
|
end
|
25
|
-
|
25
|
+
mixin_receiver.send(:extend, self.much_mixin_class_methods_module)
|
26
26
|
|
27
|
-
self.
|
27
|
+
self.much_mixin_instance_method_blocks.each do |block|
|
28
28
|
self.much_mixin_instance_methods_module.class_eval(&block)
|
29
29
|
end
|
30
|
-
|
30
|
+
mixin_receiver.send(:include, self.much_mixin_instance_methods_module)
|
31
31
|
|
32
|
-
self.
|
33
|
-
|
32
|
+
self.much_mixin_after_included_blocks.each do |block|
|
33
|
+
mixin_receiver.class_eval(&block)
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
#
|
38
|
-
# the
|
39
|
-
# methods to the
|
40
|
-
#
|
41
|
-
#
|
37
|
+
# The included detector is an empty module that is only used to detect if
|
38
|
+
# the mix-in has been included or not. It doesn't add any behavior or
|
39
|
+
# methods to the receiver and uses `const_set` to name the module so if its
|
40
|
+
# seen in the ancestors it doesn't look like some random module and it can
|
41
|
+
# be tracked back to much-mixin.
|
42
42
|
def much_mixin_included_detector
|
43
43
|
@much_mixin_included_detector ||= Module.new.tap do |m|
|
44
44
|
self.const_set("MuchMixinIncludedDetector", m)
|
@@ -61,36 +61,32 @@ module MuchMixin
|
|
61
61
|
@much_mixin_included_blocks ||= []
|
62
62
|
end
|
63
63
|
|
64
|
-
def
|
65
|
-
@
|
64
|
+
def much_mixin_after_included_blocks
|
65
|
+
@much_mixin_after_included_blocks ||= []
|
66
66
|
end
|
67
67
|
|
68
|
-
def
|
69
|
-
@
|
68
|
+
def much_mixin_class_method_blocks
|
69
|
+
@much_mixin_class_method_blocks ||= []
|
70
70
|
end
|
71
71
|
|
72
|
-
def
|
73
|
-
@
|
72
|
+
def much_mixin_instance_method_blocks
|
73
|
+
@much_mixin_instance_method_blocks ||= []
|
74
74
|
end
|
75
75
|
|
76
76
|
def mixin_included(&block)
|
77
77
|
self.much_mixin_included_blocks << block
|
78
78
|
end
|
79
|
-
alias_method :plugin_included, :mixin_included
|
80
79
|
|
81
80
|
def after_mixin_included(&block)
|
82
|
-
self.
|
81
|
+
self.much_mixin_after_included_blocks << block
|
83
82
|
end
|
84
|
-
alias_method :after_plugin_included, :after_mixin_included
|
85
83
|
|
86
84
|
def mixin_class_methods(&block)
|
87
|
-
self.
|
85
|
+
self.much_mixin_class_method_blocks << block
|
88
86
|
end
|
89
|
-
alias_method :plugin_class_methods, :mixin_class_methods
|
90
87
|
|
91
88
|
def mixin_instance_methods(&block)
|
92
|
-
self.
|
89
|
+
self.much_mixin_instance_method_blocks << block
|
93
90
|
end
|
94
|
-
alias_method :plugin_instance_methods, :mixin_instance_methods
|
95
91
|
end
|
96
92
|
end
|
data/lib/much-mixin/version.rb
CHANGED
@@ -11,15 +11,15 @@ module MuchMixin
|
|
11
11
|
end
|
12
12
|
subject{ @my_class }
|
13
13
|
|
14
|
-
should "class eval the
|
14
|
+
should "class eval the mix-in included block on MyClass" do
|
15
15
|
assert_equal "another", subject.another
|
16
16
|
end
|
17
17
|
|
18
|
-
should "add the
|
18
|
+
should "add the mix-in class methods to MyClass" do
|
19
19
|
assert_equal "a-class-method", MyClass.a_class_method
|
20
20
|
end
|
21
21
|
|
22
|
-
should "add the
|
22
|
+
should "add the mix-in instance methods to MyClass" do
|
23
23
|
assert_equal "an-instance-method", subject.an_instance_method
|
24
24
|
end
|
25
25
|
|
@@ -25,9 +25,9 @@ module MuchMixin
|
|
25
25
|
assert_same exp, subject.much_mixin_included_detector
|
26
26
|
end
|
27
27
|
|
28
|
-
should "have no
|
28
|
+
should "have no mix-in included blocks by default" do
|
29
29
|
assert_empty subject.much_mixin_included_blocks
|
30
|
-
assert_empty subject.
|
30
|
+
assert_empty subject.much_mixin_after_included_blocks
|
31
31
|
end
|
32
32
|
|
33
33
|
should "append blocks" do
|
@@ -52,7 +52,7 @@ module MuchMixin
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
should "call the
|
55
|
+
should "call the mix-in included blocks" do
|
56
56
|
assert_equal 0, @receiver.block1_count
|
57
57
|
assert_equal 0, @receiver.block2_count
|
58
58
|
assert_equal 0, @receiver.do_something_count
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: much-mixin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kelly Redding
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-01-
|
12
|
+
date: 2021-01-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: assert
|
@@ -40,13 +40,11 @@ files:
|
|
40
40
|
- bench/script.rb
|
41
41
|
- lib/much-mixin.rb
|
42
42
|
- lib/much-mixin/version.rb
|
43
|
-
- lib/much-plugin.rb
|
44
43
|
- log/.gitkeep
|
45
44
|
- much-mixin.gemspec
|
46
45
|
- test/helper.rb
|
47
46
|
- test/support/factory.rb
|
48
47
|
- test/system/much-mixin_tests.rb
|
49
|
-
- test/system/much-plugin_tests.rb
|
50
48
|
- test/unit/much-mixin_tests.rb
|
51
49
|
- tmp/.gitkeep
|
52
50
|
homepage: http://github.com/redding/much-mixin
|
@@ -76,5 +74,4 @@ test_files:
|
|
76
74
|
- test/helper.rb
|
77
75
|
- test/support/factory.rb
|
78
76
|
- test/system/much-mixin_tests.rb
|
79
|
-
- test/system/much-plugin_tests.rb
|
80
77
|
- test/unit/much-mixin_tests.rb
|
data/lib/much-plugin.rb
DELETED
@@ -1,56 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "assert"
|
4
|
-
require "much-plugin"
|
5
|
-
|
6
|
-
module MuchMixin
|
7
|
-
class SystemTests < Assert::Context
|
8
|
-
desc "MuchMixin"
|
9
|
-
setup do
|
10
|
-
@my_class = MyClass.new
|
11
|
-
end
|
12
|
-
subject{ @my_class }
|
13
|
-
|
14
|
-
should "class eval the plugin included block on MyClass" do
|
15
|
-
assert_equal "another", subject.another
|
16
|
-
end
|
17
|
-
|
18
|
-
should "add the plugin class methods to MyClass" do
|
19
|
-
assert_equal "a-class-method", MyClass.a_class_method
|
20
|
-
end
|
21
|
-
|
22
|
-
should "add the plugin instance methods to MyClass" do
|
23
|
-
assert_equal "an-instance-method", subject.an_instance_method
|
24
|
-
end
|
25
|
-
|
26
|
-
module AnotherMixin
|
27
|
-
def another
|
28
|
-
"another"
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
module MyMuchMixin
|
33
|
-
include MuchMixin
|
34
|
-
|
35
|
-
mixin_included do
|
36
|
-
include AnotherMixin
|
37
|
-
end
|
38
|
-
|
39
|
-
mixin_class_methods do
|
40
|
-
def a_class_method
|
41
|
-
"a-class-method"
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
mixin_instance_methods do
|
46
|
-
def an_instance_method
|
47
|
-
"an-instance-method"
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
class MyClass
|
53
|
-
include MyMuchMixin
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|