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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 28fac94ed0a9f228774a872d2a0300825f5eb92c0e7b382af265936f21abd30b
4
- data.tar.gz: 42992da0c84c834ac2b864fb08a02fa9dd4c252d143512052cdc9cfbde46e8e4
3
+ metadata.gz: 622a26403cc037812349be1ac6393a9b267edabab50137fb0fa22822a22bbd74
4
+ data.tar.gz: e4f1741bf4d76cbf19801e28c444b13d1d105c1904f6ceb25521f9661e9551bd
5
5
  SHA512:
6
- metadata.gz: c2229eca4fda26cb23d960904055554436682e86a7bf2c760042727024f65d84691d721313a67c35226af2032034ae89065cd8a7105294644ddc19e0cc592f7e
7
- data.tar.gz: c3acfab039cea2a7de5177b46fa4e47603626f0890927960dd59bbb4c38d1292b69188b2d783a52bd4f077a8c14c576e60fc159ae00602ee5c3108f11a6dbae8
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 other mixins that act as "plugins" to other components. Define included hooks using `mixin_included` that will be class eval'd in the scope of the receiver.
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 plugin is mixed in multiple times on the same receiver.
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 plugin receivers:
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 plugin class/instance methods have been evaluated. E.g. use this to call a class method that the plugin defines.
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
- configure_the_plugin
59
+ configure_the_mixin
60
60
  end
61
61
 
62
62
  mixin_class_methods do
63
- def configure_the_plugin
63
+ def configure_the_mixin
64
64
  # ...
65
65
  end
66
66
  end
@@ -8,37 +8,37 @@ module MuchMixin
8
8
  end
9
9
 
10
10
  module ClassMethods
11
- # install an included block that first checks if this plugin's receiver mixin
12
- # has already been included. If it has not been, include the receiver mixin
13
- # and run all of the `mixin_included` blocks
14
- def included(plugin_receiver)
15
- return if plugin_receiver.include?(self.much_mixin_included_detector)
16
- plugin_receiver.send(:include, self.much_mixin_included_detector)
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
- plugin_receiver.class_eval(&block)
19
+ mixin_receiver.class_eval(&block)
20
20
  end
21
21
 
22
- self.much_plugin_class_method_blocks.each do |block|
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
- plugin_receiver.send(:extend, self.much_mixin_class_methods_module)
25
+ mixin_receiver.send(:extend, self.much_mixin_class_methods_module)
26
26
 
27
- self.much_plugin_instance_method_blocks.each do |block|
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
- plugin_receiver.send(:include, self.much_mixin_instance_methods_module)
30
+ mixin_receiver.send(:include, self.much_mixin_instance_methods_module)
31
31
 
32
- self.much_plugin_after_included_blocks.each do |block|
33
- plugin_receiver.class_eval(&block)
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
- # the included detector is an empty module that is only used to detect if
38
- # the plugin has been included or not, it doesn't add any behavior or
39
- # methods to the object receiving the plugin; we use `const_set` to name the
40
- # module so if its seen in the ancestors it doesn't look like some random
41
- # module and it can be tracked back to much-mixin
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 much_plugin_after_included_blocks
65
- @much_plugin_after_included_blocks ||= []
64
+ def much_mixin_after_included_blocks
65
+ @much_mixin_after_included_blocks ||= []
66
66
  end
67
67
 
68
- def much_plugin_class_method_blocks
69
- @much_plugin_class_method_blocks ||= []
68
+ def much_mixin_class_method_blocks
69
+ @much_mixin_class_method_blocks ||= []
70
70
  end
71
71
 
72
- def much_plugin_instance_method_blocks
73
- @much_plugin_instance_method_blocks ||= []
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.much_plugin_after_included_blocks << block
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.much_plugin_class_method_blocks << block
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.much_plugin_instance_method_blocks << block
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MuchMixin
4
- VERSION = "0.0.1"
4
+ VERSION = "0.2.3"
5
5
  end
@@ -11,15 +11,15 @@ module MuchMixin
11
11
  end
12
12
  subject{ @my_class }
13
13
 
14
- should "class eval the plugin included block on MyClass" do
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 plugin class methods to MyClass" do
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 plugin instance methods to MyClass" do
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 plugin included blocks by default" do
28
+ should "have no mix-in included blocks by default" do
29
29
  assert_empty subject.much_mixin_included_blocks
30
- assert_empty subject.much_plugin_after_included_blocks
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 plugin included blocks" do
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.0.1
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-05 00:00:00.000000000 Z
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
@@ -1,3 +0,0 @@
1
- require "much-mixin"
2
-
3
- MuchPlugin = MuchMixin
@@ -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