pluginator 0.11.1 → 0.11.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 +4 -4
- data/README.md +34 -4
- data/lib/pluginator/autodetect.rb +10 -5
- data/lib/pluginator/extendable_autodetect.rb +1 -1
- data/lib/pluginator/version.rb +1 -1
- data/lib/plugins/pluginator/extensions/matching.rb +2 -2
- data/test/autodetect_test.rb +8 -1
- data/test/plugins/extensions/matching_test.rb +4 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f705fb41a885499f22f36ff1790aee25a172d3b3
|
4
|
+
data.tar.gz: 7ab13d20196c4e9a88a7847d3348dce7c926e1f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9c9ec1df7f0bb5b9f1645c53dfd40e822a10ad4373742b14ebcfdd2fa273444e6277a729e2fc8732ade2563b47ec66bb0b54c575522895682d12821e9d3b6ee
|
7
|
+
data.tar.gz: 46d993a9bc68ddd98539932ed2f430e50d1170239001665770c7cc20a869652db1d2f2345145468a81c9508247be560d9e68e97ed2a8504398fa5b91360bbaff
|
data/README.md
CHANGED
@@ -35,12 +35,42 @@ type_plugins = rvm2plugins["<type>"]
|
|
35
35
|
types = rvm2plugins.types
|
36
36
|
```
|
37
37
|
|
38
|
-
##
|
38
|
+
## Usage
|
39
39
|
|
40
40
|
```ruby
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
Pluginator.find("<group>") => Pluginator object
|
42
|
+
plugins = Pluginator.find("<group>", type: "<type>", extends: %i{<extensions>})
|
43
|
+
plugins["<type>"] => Array of plugins
|
44
|
+
plugins.type => Array of plugins for type defined with `type: "<type>"`
|
45
|
+
plugins.types => Array of types
|
46
|
+
```
|
47
|
+
|
48
|
+
- `"<group>"` - Load plugins for given group.
|
49
|
+
- `type: "<type>"` - Load plugins only of given type, makes `type` method accessible.
|
50
|
+
- `extends: %i{<extensions>}` - Extend pluginator with given extensions.
|
51
|
+
|
52
|
+
## Extensions
|
53
|
+
|
54
|
+
Pluginator comes with few handful extensions.
|
55
|
+
|
56
|
+
### First ask
|
57
|
+
|
58
|
+
Call a method on plugin and return first one that returns `true`.
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
plugins = Pluginator.find("<group>", extends: %i{first_ask})
|
62
|
+
plugins.first_ask( "<type>", "method_to_call", *params) => plugin or nil
|
63
|
+
plugins.first_ask!("<type>", "method_to_call", *params) => plugin or exception PluginatorError
|
64
|
+
```
|
65
|
+
|
66
|
+
### Matching
|
67
|
+
|
68
|
+
Map array of names to available plugins.
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
plugins = Pluginator.find("<group>", extends: %i{matching})
|
72
|
+
plugins.matching( "<type>", [<array_of_names>]) => [plugins] # nil for missing ones
|
73
|
+
plugins.matching!("<type>", [<array_of_names>]) => [plugins] or exception PluginatorError
|
44
74
|
```
|
45
75
|
|
46
76
|
## Examples
|
@@ -10,19 +10,24 @@ module Pluginator
|
|
10
10
|
setup_autodetect(type)
|
11
11
|
end
|
12
12
|
|
13
|
-
def type
|
14
|
-
@plugins[@force_type]
|
15
|
-
end
|
16
|
-
|
17
13
|
private
|
18
14
|
|
19
15
|
include NameConverter
|
20
16
|
|
21
17
|
def setup_autodetect(type)
|
22
|
-
|
18
|
+
force_type(type)
|
23
19
|
load_files(find_files)
|
24
20
|
end
|
25
21
|
|
22
|
+
def force_type(type)
|
23
|
+
@force_type = type
|
24
|
+
unless @force_type.nil?
|
25
|
+
define_singleton_method(:type) do
|
26
|
+
@plugins[@force_type]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
26
31
|
def find_files
|
27
32
|
Gem.find_files(file_name_pattern(@group, @force_type))
|
28
33
|
end
|
data/lib/pluginator/version.rb
CHANGED
@@ -6,13 +6,13 @@ module Pluginator::Extensions
|
|
6
6
|
include PluginsMap
|
7
7
|
include Conversions
|
8
8
|
|
9
|
-
def
|
9
|
+
def matching(type, list)
|
10
10
|
list.map do |plugin|
|
11
11
|
(plugins_map(type) || {})[string2class(plugin)]
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
def
|
15
|
+
def matching!(type, list)
|
16
16
|
@plugins[type] or raise Pluginator::MissingType.new(type, @plugins.types)
|
17
17
|
list.map do |plugin|
|
18
18
|
plugin = string2class(plugin)
|
data/test/autodetect_test.rb
CHANGED
@@ -53,7 +53,7 @@ describe Pluginator::Autodetect do
|
|
53
53
|
end
|
54
54
|
|
55
55
|
it "finds files group and existing type" do
|
56
|
-
@pluginator.
|
56
|
+
@pluginator.send(:force_type, "math")
|
57
57
|
@pluginator.type.must_equal( @pluginator["math"] )
|
58
58
|
end
|
59
59
|
|
@@ -95,8 +95,15 @@ describe Pluginator::Autodetect do
|
|
95
95
|
it "hides methods" do
|
96
96
|
pluginator = Pluginator::Autodetect.new("something")
|
97
97
|
pluginator.public_methods.must_include(:register_plugin)
|
98
|
+
pluginator.public_methods.wont_include(:type)
|
98
99
|
pluginator.public_methods.wont_include(:load_plugins)
|
99
100
|
pluginator.public_methods.wont_include(:split_file_name)
|
100
101
|
end
|
101
102
|
|
103
|
+
it "defines type method dynamically" do
|
104
|
+
Pluginator::Autodetect.new("something").public_methods.wont_include(:type)
|
105
|
+
Pluginator::Autodetect.new("something", type: 'math').public_methods.must_include(:type)
|
106
|
+
Pluginator::Autodetect.new("something").public_methods.wont_include(:type)
|
107
|
+
end
|
108
|
+
|
102
109
|
end
|
@@ -17,20 +17,20 @@ describe Pluginator::Extensions::Matching do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
it "finds existing plugin" do
|
20
|
-
@tester.
|
20
|
+
@tester.matching("extensions", ["plugins_map"]).must_equal( [Pluginator::Extensions::PluginsMap] )
|
21
21
|
end
|
22
22
|
|
23
23
|
it "finds existing plugin - no exception" do
|
24
|
-
@tester.
|
24
|
+
@tester.matching!("extensions", ["plugins_map"]).must_equal( [Pluginator::Extensions::PluginsMap] )
|
25
25
|
end
|
26
26
|
|
27
27
|
it "does not find missing plugin - no exception" do
|
28
|
-
@tester.
|
28
|
+
@tester.matching("extensions", ["plugins_map2"]).must_equal( [nil] )
|
29
29
|
end
|
30
30
|
|
31
31
|
it "finds existing plugin" do
|
32
32
|
lambda {
|
33
|
-
@tester.
|
33
|
+
@tester.matching!("extensions", ["plugins_map2"])
|
34
34
|
}.must_raise(Pluginator::MissingPlugin)
|
35
35
|
end
|
36
36
|
end
|