pluginator 0.11.2 → 0.11.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
  SHA1:
3
- metadata.gz: f705fb41a885499f22f36ff1790aee25a172d3b3
4
- data.tar.gz: 7ab13d20196c4e9a88a7847d3348dce7c926e1f1
3
+ metadata.gz: b6454fa655abb05e55461de618af2de74dcdecf1
4
+ data.tar.gz: eae4963322e3dd0ea9892c1965c5384131f728b8
5
5
  SHA512:
6
- metadata.gz: b9c9ec1df7f0bb5b9f1645c53dfd40e822a10ad4373742b14ebcfdd2fa273444e6277a729e2fc8732ade2563b47ec66bb0b54c575522895682d12821e9d3b6ee
7
- data.tar.gz: 46d993a9bc68ddd98539932ed2f430e50d1170239001665770c7cc20a869652db1d2f2345145468a81c9508247be560d9e68e97ed2a8504398fa5b91360bbaff
6
+ metadata.gz: 5a7e5992fb6a1203cb9a45681e8719b2d7a9836ffafeb1312b866275c1b9973d95bbdbba4ecd83ba8e4ec9d6ab0f6d83698dc39ece10dffd7566b73f5be783f8
7
+ data.tar.gz: 0f19687c93b7ba4b14ac848308bdbd5eb4ee15903b29333c6f1880e845d742cde3a7a53090380596ca2121b8a267907a7386ac22c07113774e019c2b07692979
@@ -1,3 +1,3 @@
1
1
  module Pluginator
2
- VERSION = "0.11.2"
2
+ VERSION = "0.11.3"
3
3
  end
@@ -0,0 +1,20 @@
1
+ require_relative "plugins_map"
2
+ require_relative "conversions"
3
+
4
+ module Pluginator::Extensions
5
+ module FirstClass
6
+ include PluginsMap
7
+ include Conversions
8
+
9
+ def first_class(type, klass)
10
+ (plugins_map(type) || {})[string2class(klass)]
11
+ end
12
+
13
+ def first_class!(type, klass)
14
+ @plugins[type] or raise Pluginator::MissingType.new(type, @plugins.keys)
15
+ klass = string2class(klass)
16
+ plugins_map(type)[klass] or
17
+ raise Pluginator::MissingPlugin.new(type, klass, plugins_map(type).keys)
18
+ end
19
+ end
20
+ end
@@ -13,7 +13,7 @@ module Pluginator::Extensions
13
13
  end
14
14
 
15
15
  def matching!(type, list)
16
- @plugins[type] or raise Pluginator::MissingType.new(type, @plugins.types)
16
+ @plugins[type] or raise Pluginator::MissingType.new(type, @plugins.keys)
17
17
  list.map do |plugin|
18
18
  plugin = string2class(plugin)
19
19
  plugins_map(type)[plugin] or
@@ -0,0 +1,48 @@
1
+ require 'test_helper'
2
+ require 'plugins/pluginator/extensions/first_class'
3
+ require 'plugins/something/stats/max'
4
+
5
+ module Something
6
+ module Stats; end
7
+ end
8
+
9
+ class FirstClassTester
10
+ attr_accessor :plugins
11
+ include Pluginator::Extensions::FirstClass
12
+ end
13
+
14
+ describe Pluginator::Extensions::FirstClass do
15
+ before do
16
+ @tester = FirstClassTester.new
17
+ @tester.plugins = { "stats" => [
18
+ Something::Stats::Max
19
+ ] }
20
+ end
21
+
22
+ it "finds existing plugin" do
23
+ @tester.first_class("stats", "max").must_equal( Something::Stats::Max )
24
+ end
25
+
26
+ it "finds proper plugin" do
27
+ @tester.first_class("stats", "max").action.must_equal( 42 )
28
+ end
29
+
30
+ it "finds existing plugin - no exception" do
31
+ @tester.first_class!("stats", "max").must_equal( Something::Stats::Max )
32
+ end
33
+
34
+ it "does not find missing plugin - no exception" do
35
+ @tester.first_class("stats", "min").must_equal( nil )
36
+ end
37
+
38
+ it "does not find missing plugin - exception plugin" do
39
+ lambda {
40
+ @tester.first_class!("stats", "min")
41
+ }.must_raise(Pluginator::MissingPlugin)
42
+ end
43
+ it "does not find missing plugin - exception type" do
44
+ lambda {
45
+ @tester.first_class!("stats2", "max")
46
+ }.must_raise(Pluginator::MissingType)
47
+ end
48
+ 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.2
4
+ version: 0.11.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michal Papis
@@ -76,6 +76,7 @@ files:
76
76
  - lib/pluginator/version.rb
77
77
  - lib/plugins/pluginator/extensions/conversions.rb
78
78
  - lib/plugins/pluginator/extensions/first_ask.rb
79
+ - lib/plugins/pluginator/extensions/first_class.rb
79
80
  - lib/plugins/pluginator/extensions/matching.rb
80
81
  - lib/plugins/pluginator/extensions/plugins_map.rb
81
82
  - pluginator.gemspec
@@ -85,6 +86,7 @@ files:
85
86
  - test/name_converter_test.rb
86
87
  - test/plugins/extensions/conversions_test.rb
87
88
  - test/plugins/extensions/first_ask_test.rb
89
+ - test/plugins/extensions/first_class_test.rb
88
90
  - test/plugins/extensions/matching_test.rb
89
91
  - test/plugins/extensions/plugins_map_test.rb
90
92
  - test/test_helper.rb
@@ -118,6 +120,7 @@ test_files:
118
120
  - test/name_converter_test.rb
119
121
  - test/plugins/extensions/conversions_test.rb
120
122
  - test/plugins/extensions/first_ask_test.rb
123
+ - test/plugins/extensions/first_class_test.rb
121
124
  - test/plugins/extensions/matching_test.rb
122
125
  - test/plugins/extensions/plugins_map_test.rb
123
126
  - test/test_helper.rb