much-plugin 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: baebd1ccaff9c505af4deac64f758ccad4a5f41a8bc5e94ad3fd3bdcc6a6a8cb
4
- data.tar.gz: 8da8eca30eb1766bb3d3c5b0beab9a271a0b27ac7c2d281d169b0f7b4be0110f
3
+ metadata.gz: fbaad5b7dab33dc311e475f220cfbfc341f7def78de5fbf58d0f73b1663d6824
4
+ data.tar.gz: 6fad28bbd725bd87257f6c6e60e9cce2467a0f5ae5ab81b4030b7c266a419abd
5
5
  SHA512:
6
- metadata.gz: 66e7398810226de3fda5cc76e8c298f15a8e38b1b56647e6abd9751c9469fd2f2919fbfd668747807e68b274304ecc3f08035c0341c596abcf2a45458cb2d56f
7
- data.tar.gz: dbdaf8782afdad32471fdf75eba18e7ac05f1dc423167808fdb4794ae1c2a3cf924d2009685fcaf353c74fc15bcc519d660f351c302c2072de2223e827f9078f
6
+ metadata.gz: b2fce8bb616549534a12f8532dcf4efcc23306ea1cfba943ec7360c7ee07645fef72ac412e983369685c6df477c51f3be04c0b583b3a7357a6db026db6c7858f
7
+ data.tar.gz: 4321146b24ba6f7cdebecfa094f63bb3244996188df4d03b609a14c1cbc876cb3f06dc8d747ca1256aae0c7ba077ba3b68b7197c851fe86dae0639d11de1a11b
data/Gemfile CHANGED
@@ -2,7 +2,7 @@ source "https://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- gem 'pry', "~> 0.9.0"
5
+ gem "pry", "~> 0.12.2"
6
6
 
7
7
  # to release, uncomment this and run `bundle exec ggem r -f`
8
8
  gem 'ggem'
data/README.md CHANGED
@@ -45,6 +45,28 @@ module MyPluginMixin
45
45
  end
46
46
  ```
47
47
 
48
+ ### `after_plugin_included`
49
+
50
+ These hooks work just like the `plugin_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.
51
+
52
+ ```ruby
53
+ requre "much-plugin"
54
+
55
+ module MyPluginMixin
56
+ include MuchPlugin
57
+
58
+ after_plugin_included do
59
+ configure_the_plugin
60
+ end
61
+
62
+ plugin_class_methods do
63
+ def configure_the_plugin
64
+ # ...
65
+ end
66
+ end
67
+ end
68
+ ```
69
+
48
70
  ## Example
49
71
 
50
72
  ```ruby
@@ -26,6 +26,10 @@ module MuchPlugin
26
26
  self.much_plugin_instance_methods_module.class_eval(&block)
27
27
  end
28
28
  plugin_receiver.send(:include, self.much_plugin_instance_methods_module)
29
+
30
+ self.much_plugin_after_included_blocks.each do |block|
31
+ plugin_receiver.class_eval(&block)
32
+ end
29
33
  end
30
34
 
31
35
  # the included detector is an empty module that is only used to detect if
@@ -55,6 +59,10 @@ module MuchPlugin
55
59
  @much_plugin_included_blocks ||= []
56
60
  end
57
61
 
62
+ def much_plugin_after_included_blocks
63
+ @much_plugin_after_included_blocks ||= []
64
+ end
65
+
58
66
  def much_plugin_class_method_blocks
59
67
  @much_plugin_class_method_blocks ||= []
60
68
  end
@@ -67,6 +75,10 @@ module MuchPlugin
67
75
  self.much_plugin_included_blocks << block
68
76
  end
69
77
 
78
+ def after_plugin_included(&block)
79
+ self.much_plugin_after_included_blocks << block
80
+ end
81
+
70
82
  def plugin_class_methods(&block)
71
83
  self.much_plugin_class_method_blocks << block
72
84
  end
@@ -1,3 +1,3 @@
1
1
  module MuchPlugin
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -18,6 +18,6 @@ Gem::Specification.new do |gem|
18
18
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
19
  gem.require_paths = ["lib"]
20
20
 
21
- gem.add_development_dependency("assert", ["~> 2.17.0"])
21
+ gem.add_development_dependency("assert", ["~> 2.18.1"])
22
22
 
23
23
  end
@@ -13,7 +13,7 @@ module MuchPlugin
13
13
  subject{ @plugin }
14
14
 
15
15
  should have_imeths :much_plugin_included_detector, :much_plugin_included_blocks
16
- should have_imeths :plugin_included
16
+ should have_imeths :plugin_included, :after_plugin_included
17
17
 
18
18
  should "know its included detector" do
19
19
  mixin = subject.much_plugin_included_detector
@@ -25,6 +25,7 @@ module MuchPlugin
25
25
 
26
26
  should "have no plugin included blocks by default" do
27
27
  assert_empty subject.much_plugin_included_blocks
28
+ assert_empty subject.much_plugin_after_included_blocks
28
29
  end
29
30
 
30
31
  should "append blocks" do
@@ -44,17 +45,21 @@ module MuchPlugin
44
45
  def self.block1_count; @block1_count ||= 0; end
45
46
  def self.inc_block2; @block2_count ||= 0; @block2_count += 1; end
46
47
  def self.block2_count; @block2_count ||= 0; end
48
+
49
+ def self.do_something_count; @do_something_count ||= 0; end
47
50
  end
48
51
  end
49
52
 
50
53
  should "call the plugin included blocks" do
51
54
  assert_equal 0, @receiver.block1_count
52
55
  assert_equal 0, @receiver.block2_count
56
+ assert_equal 0, @receiver.do_something_count
53
57
 
54
58
  @receiver.send(:include, TestPlugin)
55
59
 
56
60
  assert_equal 1, @receiver.block1_count
57
61
  assert_equal 1, @receiver.block2_count
62
+ assert_equal 1, @receiver.do_something_count
58
63
  end
59
64
 
60
65
  should "call blocks only once no matter even if previously mixed in" do
@@ -62,11 +67,13 @@ module MuchPlugin
62
67
 
63
68
  assert_equal 1, @receiver.block1_count
64
69
  assert_equal 1, @receiver.block2_count
70
+ assert_equal 1, @receiver.do_something_count
65
71
 
66
72
  @receiver.send(:include, TestPlugin)
67
73
 
68
74
  assert_equal 1, @receiver.block1_count
69
75
  assert_equal 1, @receiver.block2_count
76
+ assert_equal 1, @receiver.do_something_count
70
77
  end
71
78
 
72
79
  should "call blocks only once even if mixed in by a 3rd party" do
@@ -79,23 +86,37 @@ module MuchPlugin
79
86
 
80
87
  assert_equal 1, @receiver.block1_count
81
88
  assert_equal 1, @receiver.block2_count
89
+ assert_equal 1, @receiver.do_something_count
82
90
 
83
91
  @receiver.send(:include, TestPlugin)
84
92
 
85
93
  assert_equal 1, @receiver.block1_count
86
94
  assert_equal 1, @receiver.block2_count
95
+ assert_equal 1, @receiver.do_something_count
87
96
 
88
97
  @receiver.send(:include, third_party)
89
98
 
90
99
  assert_equal 1, @receiver.block1_count
91
100
  assert_equal 1, @receiver.block2_count
101
+ assert_equal 1, @receiver.do_something_count
92
102
  end
93
103
 
94
- TestPlugin = Module.new do
95
- include MuchPlugin
96
-
97
- plugin_included{ inc_block1 }
98
- plugin_included{ inc_block2 }
99
- end
104
+ TestPlugin =
105
+ Module.new do
106
+ include MuchPlugin
107
+
108
+ plugin_included{ inc_block1 }
109
+ after_plugin_included{
110
+ inc_block2
111
+ do_something
112
+ }
113
+
114
+ plugin_class_methods do
115
+ def do_something
116
+ @do_something_count ||= 0
117
+ @do_something_count += 1
118
+ end
119
+ end
120
+ end
100
121
  end
101
122
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: much-plugin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
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: 2019-09-03 00:00:00.000000000 Z
12
+ date: 2020-06-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: assert
@@ -17,14 +17,14 @@ dependencies:
17
17
  requirements:
18
18
  - - "~>"
19
19
  - !ruby/object:Gem::Version
20
- version: 2.17.0
20
+ version: 2.18.1
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
- version: 2.17.0
27
+ version: 2.18.1
28
28
  description: An API to ensure mixin included logic (the "plugin") only runs once.
29
29
  email:
30
30
  - kelly@kellyredding.com
@@ -66,8 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
66
66
  - !ruby/object:Gem::Version
67
67
  version: '0'
68
68
  requirements: []
69
- rubyforge_project:
70
- rubygems_version: 2.7.7
69
+ rubygems_version: 3.1.2
71
70
  signing_key:
72
71
  specification_version: 4
73
72
  summary: An API to ensure mixin included logic (the "plugin") only runs once.