pluginator 0.10.0 → 0.10.1

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
  SHA1:
3
- metadata.gz: 4c2d1a80503ff918471f6e8477ac36987d7ae8bf
4
- data.tar.gz: 0902865fc2f708aeb692a647cb4c0a8af808ecc1
3
+ metadata.gz: 59d64edff8d110c4973f3904dc82b87169e5df85
4
+ data.tar.gz: bfcaaf2bd8c78b659be273bef544cfaa11d5b852
5
5
  SHA512:
6
- metadata.gz: ef24dd58904758e1ab42b0f8db5c6677b4c5d3ac0aca1551984c294cc06c0138282de6a5aaecb2e73540b8941399ebfd9e8352f221cc84dcb431e79f33c54c4b
7
- data.tar.gz: 297af16db59fb91ae6b9fa1c66bff269bb38da2be00e13c87050ef1fa48f706af74deae591be4d0ef2ac7cd772d9bd9de8c2c91bd39a9db6eca14107b8705d73
6
+ metadata.gz: b7a922e4fc107b5ba0a0c13e5f07747bb586bf4c013e1c4d2c9bc8c7756ebab49697875a93c06e6e90e3b41174688754036811f918496f77bb5ebf492973a7f8
7
+ data.tar.gz: 7379ef2083b122ece8b36b9a38924438257246c16d3e8e3582252789e9c26d4555844bfcc8d4b2080b0a8add52a58349f5eb7aa9da3cfea8d4223d1cc7a228fc
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Pluginator
2
2
 
3
+ [![Code Climate](https://codeclimate.com/github/rvm/pluginator.png)](https://codeclimate.com/github/rvm/pluginator)
4
+ [![Build Status](https://travis-ci.org/rvm/pluginator.png?branch=master)](https://travis-ci.org/rvm/pluginator)
5
+ [![Dependency Status](https://gemnasium.com/rvm/pluginator.png)](https://gemnasium.com/rvm/pluginator)
6
+
3
7
  Gem plugin system management, detects plugins using `Gem.find_file`.
4
8
  Is only supposed with ruby 1.9.3+
5
9
 
@@ -31,6 +35,14 @@ type_plugins = rvm2plugins["<type>"]
31
35
  types = rvm2plugins.types
32
36
  ```
33
37
 
38
+ ## Loading plugins of single type
39
+
40
+ ```ruby
41
+ rvm2plugins = Pluginator::Autodetect.new("<group>", "<type>")
42
+ type_plugins = rvm2plugins["<type>"]
43
+ types = rvm2plugins.types
44
+ ```
45
+
34
46
  ## Examples
35
47
 
36
48
  ### Example 1 - task plugins
@@ -0,0 +1,5 @@
1
+ class Pluginator::Stats::Max
2
+ def self.action
3
+ 42
4
+ end
5
+ end
@@ -4,8 +4,9 @@ require_relative "name_converter"
4
4
  module Pluginator
5
5
  class Autodetect < Group
6
6
 
7
- def initialize(group)
7
+ def initialize(group, type=nil)
8
8
  super(group)
9
+ @force_type = type
9
10
  load_files(find_files)
10
11
  end
11
12
 
@@ -22,7 +23,7 @@ module Pluginator
22
23
  end
23
24
 
24
25
  def find_files
25
- Gem.find_files(file_name_pattern(@group))
26
+ Gem.find_files(file_name_pattern(@group, @force_type))
26
27
  end
27
28
 
28
29
  def load_plugin(path)
@@ -8,8 +8,8 @@ module Pluginator
8
8
  end
9
9
 
10
10
  # group => pattern
11
- def file_name_pattern(group)
12
- "plugins/#{group}/**/*.rb"
11
+ def file_name_pattern(group, type=nil)
12
+ "plugins/#{group}/#{type || "**"}/*.rb"
13
13
  end
14
14
 
15
15
  # full_name => class
@@ -1,3 +1,3 @@
1
1
  module Pluginator
2
- VERSION = "0.10.0"
2
+ VERSION = "0.10.1"
3
3
  end
@@ -1,6 +1,9 @@
1
1
  require 'minitest/autorun'
2
2
  require 'pluginator/autodetect'
3
3
 
4
+ module Pluginator::Math; end
5
+ module Pluginator::Stats; end
6
+
4
7
  def demo_file(path)
5
8
  File.expand_path(File.join("..", "..", "demo", path), __FILE__)
6
9
  end
@@ -9,11 +12,10 @@ def demo_files(*paths)
9
12
  paths.flatten.map{|path| demo_file(path) }
10
13
  end
11
14
 
12
- module Pluginator::Math; end
13
-
14
15
  describe Pluginator::Autodetect do
15
16
  before do
16
- @demo_files = demo_files("plugins/pluginator/math/increase.rb", "plugins/pluginator/math/decrease.rb")
17
+ @math_files = demo_files("plugins/pluginator/math/increase.rb", "plugins/pluginator/math/decrease.rb")
18
+ @all_files = demo_files("plugins/pluginator/math/increase.rb", "plugins/pluginator/math/decrease.rb", "plugins/pluginator/stats/max.rb")
17
19
  end
18
20
 
19
21
  describe "separate" do
@@ -30,16 +32,26 @@ describe Pluginator::Autodetect do
30
32
  File.exists?(demo_file("plugins/pluginator/math/increase.rb")).must_equal(true)
31
33
  end
32
34
 
33
- it "loads file" do
35
+ it "loads plugin" do
34
36
  @pluginator.send(:load_plugin, "plugins/pluginator/math/increase.rb")
35
37
  end
36
38
 
37
- it "finds files" do
38
- @pluginator.send(:find_files).sort.must_equal(@demo_files.sort)
39
+ it "finds files existing group" do
40
+ @pluginator.send(:find_files).sort.must_equal(@all_files.sort)
41
+ end
42
+
43
+ it "finds files group and existing type" do
44
+ @pluginator.instance_variable_set(:@force_type, "math")
45
+ @pluginator.send(:find_files).sort.must_equal(@math_files.sort)
46
+ end
47
+
48
+ it "finds files group and missing type" do
49
+ @pluginator.instance_variable_set(:@force_type, "none")
50
+ @pluginator.send(:find_files).must_equal([])
39
51
  end
40
52
 
41
- it "loads plugins" do
42
- @pluginator.send(:load_files, @demo_files)
53
+ it "loads files" do
54
+ @pluginator.send(:load_files, @math_files)
43
55
  @pluginator.types.must_include('math')
44
56
  plugins = @pluginator["math"].map(&:to_s)
45
57
  plugins.size.must_equal(2)
@@ -49,9 +61,11 @@ describe Pluginator::Autodetect do
49
61
  end
50
62
  end
51
63
 
52
- it "loads plugins automatically" do
64
+ it "loads plugins automatically for group" do
53
65
  pluginator = Pluginator::Autodetect.new("pluginator")
66
+ pluginator.types.must_include('stats')
54
67
  pluginator.types.must_include('math')
68
+ pluginator.types.size.must_equal(2)
55
69
  plugins = pluginator["math"].map(&:to_s)
56
70
  plugins.size.must_equal(2)
57
71
  plugins.must_include("Pluginator::Math::Increase")
@@ -59,7 +73,13 @@ describe Pluginator::Autodetect do
59
73
  plugins.wont_include("Pluginator::Math::Add")
60
74
  end
61
75
 
62
- it "makes plugins work" do
76
+ it "loads plugins automatically for group/type" do
77
+ pluginator = Pluginator::Autodetect.new("pluginator", "stats")
78
+ pluginator.types.must_include('stats')
79
+ pluginator.types.size.must_equal(1)
80
+ end
81
+
82
+ it "makes group plugins work" do
63
83
  pluginator = Pluginator::Autodetect.new("pluginator")
64
84
  pluginator["math"].detect{|plugin| plugin.type == "increase" }.action(2).must_equal(3)
65
85
  pluginator["math"].detect{|plugin| plugin.type == "decrease" }.action(5).must_equal(4)
data/test/group_test.rb CHANGED
@@ -16,6 +16,7 @@ describe Pluginator::Group do
16
16
  @group.types.must_include("type1")
17
17
  @group.types.wont_include("type2")
18
18
  end
19
+
19
20
  it "adds plugin" do
20
21
  @group.register_plugin("type1", "test1")
21
22
  @group["type1"].must_include("test1")
@@ -11,9 +11,18 @@ describe Pluginator::NameConverter do
11
11
  Converter.send(:split_file_name, "/path/to/plugins/group1/type1/name1.rb", "group1").
12
12
  must_equal(["plugins/group1/type1/name1.rb", "group1/type1/name1", "type1"])
13
13
  end
14
+
14
15
  it "builds group pattern" do
15
16
  Converter.send(:file_name_pattern, "group2").must_equal("plugins/group2/**/*.rb")
16
17
  end
18
+
19
+ it "builds group/<nil> pattern" do
20
+ Converter.send(:file_name_pattern, "group2").must_equal("plugins/group2/**/*.rb")
21
+ end
22
+
23
+ it "builds group/type pattern" do
24
+ Converter.send(:file_name_pattern, "group2", "type3").must_equal("plugins/group2/type3/*.rb")
25
+ end
17
26
  end
18
27
 
19
28
  describe "classes" do
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.10.0
4
+ version: 0.10.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michal Papis
@@ -52,6 +52,7 @@ files:
52
52
  - Rakefile
53
53
  - demo/plugins/pluginator/math/decrease.rb
54
54
  - demo/plugins/pluginator/math/increase.rb
55
+ - demo/plugins/pluginator/stats/max.rb
55
56
  - lib/pluginator.rb
56
57
  - lib/pluginator/autodetect.rb
57
58
  - lib/pluginator/group.rb