pluginator 0.11.5 → 0.11.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/README.md +12 -0
- data/lib/pluginator.rb +3 -2
- data/lib/pluginator/autodetect.rb +3 -1
- data/lib/pluginator/extendable_autodetect.rb +11 -2
- data/lib/pluginator/group.rb +1 -0
- data/lib/pluginator/name_converter.rb +1 -0
- data/lib/pluginator/version.rb +1 -1
- data/lib/plugins/pluginator/extensions/class_exist.rb +20 -0
- data/lib/plugins/pluginator/extensions/conversions.rb +1 -0
- data/lib/plugins/pluginator/extensions/first_ask.rb +3 -1
- data/lib/plugins/pluginator/extensions/first_class.rb +2 -0
- data/lib/plugins/pluginator/extensions/matching.rb +1 -0
- data/lib/plugins/pluginator/extensions/plugins_map.rb +1 -0
- data/pluginator.gemspec +3 -3
- data/test/pluginator_test.rb +4 -4
- data/test/plugins/extensions/class_exist_test.rb +29 -0
- data/test/test_helper.rb +11 -2
- metadata +33 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8bf5fb904c3dd6374d8b286ee02881330767fbb1
|
4
|
+
data.tar.gz: cd84459dde760942dbd47898935f5237a486c89b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3e2d2144700cfa83112c44bc43a543ab28ba35e5eb5339a4eb26526e612c3560b006f586406eb89e58305675197cb14ef96070b8503be7c078302ee4916b4c7
|
7
|
+
data.tar.gz: d3a19e7482a755c39aaad4f582b290a8bf3c5b0afc3e522bdd537c330aa57e1d03dc56a4ebbb5a4fee3b24b8f97516fdcb13c5e26c143a78e2c99c256b266f9f
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
# Pluginator
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/pluginator.png)](http://rubygems.org/gems/pluginator)
|
3
4
|
[![Code Climate](https://codeclimate.com/github/rvm/pluginator.png)](https://codeclimate.com/github/rvm/pluginator)
|
5
|
+
[![Coverage Status](https://coveralls.io/repos/rvm/pluginator/badge.png?branch=master)](https://coveralls.io/r/rvm/pluginator?branch=master)
|
4
6
|
[![Build Status](https://travis-ci.org/rvm/pluginator.png?branch=master)](https://travis-ci.org/rvm/pluginator)
|
5
7
|
[![Dependency Status](https://gemnasium.com/rvm/pluginator.png)](https://gemnasium.com/rvm/pluginator)
|
8
|
+
[Documentation](http://rubydoc.info/gems/pluginator/frames)
|
6
9
|
|
7
10
|
Gem plugin system management, detects plugins using `Gem.find_file`.
|
8
11
|
Is only supposed with ruby 2.0.0+ (requires keyword arguments)
|
@@ -53,6 +56,15 @@ plugins.types => Array of types
|
|
53
56
|
|
54
57
|
Pluginator comes with few handful extensions.
|
55
58
|
|
59
|
+
### Class exist
|
60
|
+
|
61
|
+
Check if plugin with given class name exist.
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
plugins = Pluginator.find("<group>", extends: %i{class_exist})
|
65
|
+
plugins.class_exist?( "<type>", "<name>") => true or false
|
66
|
+
```
|
67
|
+
|
56
68
|
### First ask
|
57
69
|
|
58
70
|
Call a method on plugin and return first one that returns `true`.
|
data/lib/pluginator.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
require_relative "pluginator/extendable_autodetect"
|
2
2
|
require_relative "pluginator/version"
|
3
3
|
|
4
|
+
# A simple plugin system based on Gem.find_files
|
4
5
|
module Pluginator
|
5
6
|
# Find plugins for the given group
|
6
7
|
#
|
7
8
|
# @param group [String] name of plugins group
|
8
|
-
# @
|
9
|
-
# @
|
9
|
+
# @option type [String] name of type to load
|
10
|
+
# @option extend [Array of/or Symbol] list of extension to extend into pluginator instance
|
10
11
|
# @return instance of Pluginator
|
11
12
|
def self.find(group, type: nil, extends: [])
|
12
13
|
Pluginator::ExtendableAutodetect.new(group, type: type, extends: extends)
|
@@ -3,12 +3,14 @@ require_relative "group"
|
|
3
3
|
require_relative "name_converter"
|
4
4
|
|
5
5
|
module Pluginator
|
6
|
+
# Add autodetection capabilities to Group
|
7
|
+
# @see Group
|
6
8
|
class Autodetect < Group
|
7
9
|
|
8
10
|
# Automatically load plugins for given group (and type)
|
9
11
|
#
|
10
12
|
# @param group [String] name of the plugins group
|
11
|
-
# @
|
13
|
+
# @option type [String] name of the plugin type
|
12
14
|
def initialize(group, type: nil)
|
13
15
|
super(group)
|
14
16
|
setup_autodetect(type)
|
@@ -1,14 +1,23 @@
|
|
1
1
|
require_relative "autodetect"
|
2
2
|
|
3
3
|
module Pluginator
|
4
|
+
# Container for all Pluginator extensions,
|
5
|
+
# they are loaded in `ExtendableAutodetect`
|
6
|
+
# @see ExtendableAutodetect#extend_plugins
|
7
|
+
module Extensions
|
8
|
+
end
|
9
|
+
|
10
|
+
# Add extendability to Atudetect / Group
|
11
|
+
# @see Autodetect
|
12
|
+
# @see Group
|
4
13
|
class ExtendableAutodetect < Autodetect
|
5
14
|
|
6
15
|
# Automatically load plugins for given group (and type)
|
7
16
|
# Extend instance with extensions if given.
|
8
17
|
#
|
9
18
|
# @param group [String] name of the plugins group
|
10
|
-
# @
|
11
|
-
# @
|
19
|
+
# @option type [String] name of type to load
|
20
|
+
# @option extend [Array of/or Symbol] list of extension to extend into pluginator instance
|
12
21
|
def initialize(group, type: nil, extends: [])
|
13
22
|
super(group, type: type)
|
14
23
|
extend_plugins(extends)
|
data/lib/pluginator/group.rb
CHANGED
data/lib/pluginator/version.rb
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative "plugins_map"
|
2
|
+
require_relative "conversions"
|
3
|
+
|
4
|
+
module Pluginator::Extensions
|
5
|
+
# Extension to check if plugin for given class name exist
|
6
|
+
module ClassExist
|
7
|
+
|
8
|
+
include PluginsMap
|
9
|
+
include Conversions
|
10
|
+
|
11
|
+
# Check if plugin for given name exists.
|
12
|
+
#
|
13
|
+
# @param type [String] name of type to search for plugins
|
14
|
+
# @param klass [Symbol or String] name of the searched class
|
15
|
+
# @return [Boolean] klass exists
|
16
|
+
def class_exist?(type, klass)
|
17
|
+
!!(plugins_map(type) || {})[string2class(klass)]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -1,14 +1,16 @@
|
|
1
1
|
require_relative "plugins_map"
|
2
2
|
|
3
3
|
module Pluginator::Extensions
|
4
|
+
# Extension to find first plugin that answers the question with true
|
4
5
|
module FirstAsk
|
6
|
+
|
5
7
|
include PluginsMap
|
6
8
|
|
7
9
|
# Call a method on plugin and return first one that returns `true`.
|
8
10
|
#
|
9
11
|
# @param type [String] name of type to search for plugins
|
10
12
|
# @param method_name [Symbol] name of the method to execute
|
11
|
-
# @param
|
13
|
+
# @param params [Array] params to pass to the called method
|
12
14
|
# @return The first plugin that method call returns true
|
13
15
|
def first_ask(type, method_name, *params)
|
14
16
|
@plugins[type] or return nil
|
data/pluginator.gemspec
CHANGED
@@ -10,9 +10,9 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.version = Pluginator::VERSION
|
11
11
|
s.files = `git ls-files`.split("\n")
|
12
12
|
s.required_ruby_version = ">= 1.9.3"
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
%w{rake minitest simplecov coveralls redcarpet}.each do |name|
|
14
|
+
s.add_development_dependency(name)
|
15
|
+
end
|
16
16
|
# s.add_development_dependency("smf-gem")
|
17
17
|
s.homepage = "https://github.com/rvm/pluginator"
|
18
18
|
s.summary = "Rubygems plugin system using Gem.find_files."
|
data/test/pluginator_test.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'test_helper'
|
2
2
|
require 'pluginator'
|
3
3
|
|
4
|
-
|
5
|
-
|
4
|
+
class PluginatorTest < MiniTest::Unit::TestCase
|
5
|
+
def test_loads_plugins_automatically_for_group
|
6
6
|
pluginator = Pluginator.find("something")
|
7
7
|
pluginator.types.must_include('stats')
|
8
8
|
pluginator.types.must_include('math')
|
@@ -14,13 +14,13 @@ describe Pluginator do
|
|
14
14
|
plugins.wont_include("Something::Math::Add")
|
15
15
|
end
|
16
16
|
|
17
|
-
|
17
|
+
def test_loads_plugins_automatically_for_group_type
|
18
18
|
pluginator = Pluginator.find("something", type: "stats")
|
19
19
|
pluginator.types.must_include('stats')
|
20
20
|
pluginator.types.size.must_equal(1)
|
21
21
|
end
|
22
22
|
|
23
|
-
|
23
|
+
def test_loads_existing_extensions_symbol
|
24
24
|
pluginator = Pluginator.find("something", extends: :conversions)
|
25
25
|
pluginator.public_methods.must_include(:class2string)
|
26
26
|
pluginator.public_methods.must_include(:string2class)
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require 'plugins/pluginator/extensions/class_exist'
|
3
|
+
require 'plugins/something/stats/max'
|
4
|
+
|
5
|
+
module Something
|
6
|
+
module Stats; end
|
7
|
+
end
|
8
|
+
|
9
|
+
class ClassExistTester
|
10
|
+
attr_accessor :plugins
|
11
|
+
include Pluginator::Extensions::ClassExist
|
12
|
+
end
|
13
|
+
|
14
|
+
class Pluginator::Extensions::ClassExistTest < MiniTest::Unit::TestCase
|
15
|
+
def setup
|
16
|
+
@tester = ClassExistTester.new
|
17
|
+
@tester.plugins = { "stats" => [
|
18
|
+
Something::Stats::Max
|
19
|
+
] }
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_plugin_exist
|
23
|
+
@tester.class_exist?("stats", "max").must_equal( true )
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_plugin_missing
|
27
|
+
@tester.class_exist?("stats", "min").must_equal( false )
|
28
|
+
end
|
29
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -1,8 +1,17 @@
|
|
1
|
-
require
|
2
|
-
|
1
|
+
require "coveralls"
|
2
|
+
require "simplecov"
|
3
|
+
|
3
4
|
SimpleCov.start do
|
5
|
+
formatter SimpleCov::Formatter::MultiFormatter[
|
6
|
+
SimpleCov::Formatter::HTMLFormatter,
|
7
|
+
Coveralls::SimpleCov::Formatter,
|
8
|
+
]
|
9
|
+
command_name "Unit Tests"
|
4
10
|
add_filter "/test/"
|
5
11
|
add_filter "/demo/"
|
6
12
|
end
|
7
13
|
|
14
|
+
Coveralls.noisy = true unless ENV['CI']
|
15
|
+
|
8
16
|
require 'minitest/autorun'
|
17
|
+
require 'minitest/unit'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pluginator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.11.
|
4
|
+
version: 0.11.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michal Papis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-05-
|
11
|
+
date: 2013-05-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -52,6 +52,34 @@ dependencies:
|
|
52
52
|
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: coveralls
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: redcarpet
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
55
83
|
description:
|
56
84
|
email:
|
57
85
|
- mpapis@gmail.com
|
@@ -74,6 +102,7 @@ files:
|
|
74
102
|
- lib/pluginator/group.rb
|
75
103
|
- lib/pluginator/name_converter.rb
|
76
104
|
- lib/pluginator/version.rb
|
105
|
+
- lib/plugins/pluginator/extensions/class_exist.rb
|
77
106
|
- lib/plugins/pluginator/extensions/conversions.rb
|
78
107
|
- lib/plugins/pluginator/extensions/first_ask.rb
|
79
108
|
- lib/plugins/pluginator/extensions/first_class.rb
|
@@ -85,6 +114,7 @@ files:
|
|
85
114
|
- test/pluginator/group_test.rb
|
86
115
|
- test/pluginator/name_converter_test.rb
|
87
116
|
- test/pluginator_test.rb
|
117
|
+
- test/plugins/extensions/class_exist_test.rb
|
88
118
|
- test/plugins/extensions/conversions_test.rb
|
89
119
|
- test/plugins/extensions/first_ask_test.rb
|
90
120
|
- test/plugins/extensions/first_class_test.rb
|
@@ -120,6 +150,7 @@ test_files:
|
|
120
150
|
- test/pluginator/group_test.rb
|
121
151
|
- test/pluginator/name_converter_test.rb
|
122
152
|
- test/pluginator_test.rb
|
153
|
+
- test/plugins/extensions/class_exist_test.rb
|
123
154
|
- test/plugins/extensions/conversions_test.rb
|
124
155
|
- test/plugins/extensions/first_ask_test.rb
|
125
156
|
- test/plugins/extensions/first_class_test.rb
|