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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 177ed9844b5c23c064d42ea785fd4aa27a5a3b2a
4
- data.tar.gz: 59b7f79ca608cfa3471462d527f9e6c85a8de2ad
3
+ metadata.gz: f705fb41a885499f22f36ff1790aee25a172d3b3
4
+ data.tar.gz: 7ab13d20196c4e9a88a7847d3348dce7c926e1f1
5
5
  SHA512:
6
- metadata.gz: 17326a839cf7457e8d29096404a28f543340e44693a8615fb59b2eeb45676b56d47fbb97b8d3c463c5c97b67a454eb3fa08dcef4fb27edd88545d10480b735a8
7
- data.tar.gz: f19ec0686a73d26bf399dc3ccfd0969fbddef6a0156e000573187dc3334bd32e3e250ae325bbe5a547716c4a62bd51c43830dafceaf55d380f78687fd7a14b70
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
- ## Loading plugins of single type
38
+ ## Usage
39
39
 
40
40
  ```ruby
41
- rvm2plugins = Pluginator.find("<group>", "<type>")
42
- type_plugins = rvm2plugins["<type>"]
43
- rvm2plugins.types => ["<type>"]
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
- @force_type = type
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
@@ -30,7 +30,7 @@ module Pluginator
30
30
  end
31
31
 
32
32
  def extensions_matching(extends)
33
- pluginator_plugins.filter!("extensions", flatten_and_stringify(extends))
33
+ pluginator_plugins.matching!("extensions", flatten_and_stringify(extends))
34
34
  end
35
35
 
36
36
  end
@@ -1,3 +1,3 @@
1
1
  module Pluginator
2
- VERSION = "0.11.1"
2
+ VERSION = "0.11.2"
3
3
  end
@@ -6,13 +6,13 @@ module Pluginator::Extensions
6
6
  include PluginsMap
7
7
  include Conversions
8
8
 
9
- def filter(type, list)
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 filter!(type, list)
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)
@@ -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.instance_variable_set(:@force_type, "math")
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.filter("extensions", ["plugins_map"]).must_equal( [Pluginator::Extensions::PluginsMap] )
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.filter!("extensions", ["plugins_map"]).must_equal( [Pluginator::Extensions::PluginsMap] )
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.filter("extensions", ["plugins_map2"]).must_equal( [nil] )
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.filter!("extensions", ["plugins_map2"])
33
+ @tester.matching!("extensions", ["plugins_map2"])
34
34
  }.must_raise(Pluginator::MissingPlugin)
35
35
  end
36
36
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pluginator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.1
4
+ version: 0.11.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michal Papis