pluginator 0.11.5 → 0.11.6

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: 31df38c24119dd5089716ee8fc1edd0db9c191c6
4
- data.tar.gz: bb973079ad24dbb9f3f2fcd6fb9366ed8c7ca907
3
+ metadata.gz: 8bf5fb904c3dd6374d8b286ee02881330767fbb1
4
+ data.tar.gz: cd84459dde760942dbd47898935f5237a486c89b
5
5
  SHA512:
6
- metadata.gz: cce30736f9a11ae892b3306d33cfe5677f9f5257ce4b209986b19256187fe475314f3b096f2f53f1df5071b14b76779df86e5f161989514ecc19c95eaa5b6b12
7
- data.tar.gz: c27a85f3351e352069ed30b462fb4931fed5833f942f8f47562256c1949260dc496fe9c4e45442278f2e1ad7af5ebebd1a78acd8baf0c99df60c021453ed7328
6
+ metadata.gz: c3e2d2144700cfa83112c44bc43a543ab28ba35e5eb5339a4eb26526e612c3560b006f586406eb89e58305675197cb14ef96070b8503be7c078302ee4916b4c7
7
+ data.tar.gz: d3a19e7482a755c39aaad4f582b290a8bf3c5b0afc3e522bdd537c330aa57e1d03dc56a4ebbb5a4fee3b24b8f97516fdcb13c5e26c143a78e2c99c256b266f9f
data/.gitignore CHANGED
@@ -1,3 +1,5 @@
1
1
  /*.gem
2
2
  /Gemfile.lock
3
3
  /coverage
4
+ /doc
5
+ /.yardoc
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`.
@@ -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
- # @param type [String] optional name of type to load
9
- # @param extends optional list of extension to extend into pluginator instance
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
- # @param type [String] optional name of the plugin type
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
- # @param type [String] optional name of the plugin type
11
- # @param extends optional list of extension to extend into pluginator instance
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)
@@ -1,4 +1,5 @@
1
1
  module Pluginator
2
+ # Initial data for pluginator, includes group name and plugins
2
3
  class Group
3
4
  # Group name used for plugins
4
5
  attr_reader :group
@@ -1,4 +1,5 @@
1
1
  module Pluginator
2
+ # a helper for handling name / file / class conversions
2
3
  module NameConverter
3
4
  private
4
5
 
@@ -1,4 +1,4 @@
1
1
  module Pluginator
2
2
  # Version of Pluginator
3
- VERSION = "0.11.5"
3
+ VERSION = "0.11.6"
4
4
  end
@@ -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,4 +1,5 @@
1
1
  module Pluginator::Extensions
2
+ # a placeholder for methods to convert strings
2
3
  module Conversions
3
4
 
4
5
  # converts class name to a file name
@@ -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 *params [Array] params to pass to the called method
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
@@ -2,7 +2,9 @@ require_relative "plugins_map"
2
2
  require_relative "conversions"
3
3
 
4
4
  module Pluginator::Extensions
5
+ # Extension to find first plugin that class matches the string
5
6
  module FirstClass
7
+
6
8
  include PluginsMap
7
9
  include Conversions
8
10
 
@@ -2,6 +2,7 @@ require_relative "plugins_map"
2
2
  require_relative "conversions"
3
3
 
4
4
  module Pluginator::Extensions
5
+ # Extension to select plugins that class name matches the list of string
5
6
  module Matching
6
7
  include PluginsMap
7
8
  include Conversions
@@ -1,4 +1,5 @@
1
1
  module Pluginator::Extensions
2
+ # extend Pluginator with map of plugins: name => klass
2
3
  module PluginsMap
3
4
  # provide extra map of plugins with symbolized names as keys
4
5
  #
@@ -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
- s.add_development_dependency("rake")
14
- s.add_development_dependency("minitest")
15
- s.add_development_dependency("simplecov")
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."
@@ -1,8 +1,8 @@
1
1
  require 'test_helper'
2
2
  require 'pluginator'
3
3
 
4
- describe Pluginator do
5
- it "loads plugins automatically for group" do
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
- it "loads plugins automatically for group/type" do
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
- it "loads existing extensions - symbol" do
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
@@ -1,8 +1,17 @@
1
- require 'simplecov'
2
- SimpleCov.command_name "Unit Tests"
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.5
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-12 00:00:00.000000000 Z
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