pluginator 0.12.1 → 1.0.0

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: 3a56ec0232b4b0d3bff76ca136b14b33b0d7b232
4
- data.tar.gz: 208b160fb4e716d43afe4ed4abb7ce6fcd5efb92
3
+ metadata.gz: b70400f4d804c2f5916e9e68056db1287345f508
4
+ data.tar.gz: 5ebb958035ec8e95699a3ce44b86327acd8276c4
5
5
  SHA512:
6
- metadata.gz: d0551d4d9f432d29e2b36912817f9b4a8a738762b3cf18ba7f1c5eb565894ce9abcfc0b1358d8b5f0f4ed75348e79e61dea0bf0f34e444367fe4926e3c366341
7
- data.tar.gz: 3d33a4462c1c6f900470189c73c7dba418809264ba1cf1c45590dd71d08994e5bae676d2984e0df5ad7aa361a7bad319c5ab85fffbab71dc4c22c762d840da3e
6
+ metadata.gz: 6c51706e34d5d00c1e60406cb5c897d4e726159ee368aa7929ecd8cf2a08c911e5c05e79acc603e8eedcd63a21e2491e30e07320ae423e102e2a1d4e3335ce3d
7
+ data.tar.gz: 3f19a9c45614acaa882c289155cf0686970fbeda14390483f526573fcf87c61b4baf9547c9e15ccd5c7c1b2cf11662859d067ec8bce792154dd9e048cde0986d
data/.travis.yml CHANGED
@@ -6,6 +6,7 @@ rvm:
6
6
  - 2.0.0
7
7
  - 1.9.3
8
8
  - 1.9.2
9
+ - 1.8.7
9
10
  - rbx
10
11
  notifications:
11
12
  irc:
@@ -16,7 +17,4 @@ notifications:
16
17
  - mpapis@gmail.com
17
18
  on_failure: change
18
19
  matrix:
19
- allow_failures:
20
- - rvm: 1.9.2
21
- - rvm: rbx
22
20
  fast_finish: true
data/Gemfile CHANGED
@@ -1,12 +1,14 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- #ruby=2.1.0
3
+ #ruby=2.0.0
4
4
 
5
5
  gemspec
6
6
 
7
7
  group :development do
8
- # documentation formatting
9
- gem "redcarpet", :platforms => [:ruby]
8
+ # statistics only on MRI 2.0 - avoid problems on older rubies
9
+ gem "redcarpet", :platforms => [:mri_20]
10
+ gem "simplecov", :platforms => [:mri_20]
11
+ gem "coveralls", :platforms => [:mri_20]
10
12
 
11
13
  # rubinius support
12
14
  gem "rubysl-json", :platforms => [:rbx]
data/README.md CHANGED
@@ -95,6 +95,34 @@ plugins.matching( "<type>", [<array_of_names>]) => [plugins] # nil for missing o
95
95
  plugins.matching!("<type>", [<array_of_names>]) => [plugins] or exception PluginatorError
96
96
  ```
97
97
 
98
+ ### Your own ones
99
+
100
+ You can define your own extensions for `pluginator`, for example:
101
+
102
+ ```shell
103
+ plugins/pluginator/extensions/first_one.rb
104
+ ```
105
+
106
+ with:
107
+
108
+ ```ruby
109
+ module Pluginator::Extensions
110
+ class FirstOne
111
+ def first_one(type)
112
+ @plugins[type].first
113
+ end
114
+ end
115
+ end
116
+ ```
117
+
118
+ And now you can use it:
119
+
120
+ ```ruby
121
+ plugins = Pluginator.find("<group>", extends: %i{first_one})
122
+ plugins.first_one("<type>") => first_plugin # nil when none
123
+ ```
124
+
125
+
98
126
  ## Exceptions
99
127
 
100
128
  - `PluginatorError` - base error for all Pluginator errors
@@ -0,0 +1,6 @@
1
+ class Something::Nested::Structure::Test
2
+
3
+ def self.action
4
+ 42
5
+ end
6
+ end
@@ -1,6 +1,6 @@
1
- require_relative "errors"
2
- require_relative "group"
3
- require_relative "name_converter"
1
+ require "pluginator/errors"
2
+ require "pluginator/group"
3
+ require "pluginator/name_converter"
4
4
 
5
5
  module Pluginator
6
6
  # Add autodetection capabilities to Group
@@ -16,6 +16,10 @@ module Pluginator
16
16
  setup_autodetect(options[:type])
17
17
  end
18
18
 
19
+ def type
20
+ @plugins[@force_type] unless @force_type.nil?
21
+ end
22
+
19
23
  private
20
24
 
21
25
  include NameConverter
@@ -27,11 +31,6 @@ module Pluginator
27
31
 
28
32
  def force_type(type)
29
33
  @force_type = type
30
- unless @force_type.nil?
31
- define_singleton_method(:type) do
32
- @plugins[@force_type]
33
- end
34
- end
35
34
  end
36
35
 
37
36
  def find_files
@@ -1,4 +1,4 @@
1
- require_relative "autodetect"
1
+ require "pluginator/autodetect"
2
2
 
3
3
  module Pluginator
4
4
  # Container for all Pluginator extensions,
@@ -1,4 +1,4 @@
1
1
  module Pluginator
2
2
  # Version of Pluginator
3
- VERSION = "0.12.1"
3
+ VERSION = "1.0.0"
4
4
  end
data/lib/pluginator.rb CHANGED
@@ -1,5 +1,5 @@
1
- require_relative "pluginator/extendable_autodetect"
2
- require_relative "pluginator/version"
1
+ require "pluginator/extendable_autodetect"
2
+ require "pluginator/version"
3
3
 
4
4
  # A simple plugin system based on Gem.find_files
5
5
  module Pluginator
@@ -1,5 +1,5 @@
1
- require_relative "plugins_map"
2
- require_relative "conversions"
1
+ require "plugins/pluginator/extensions/plugins_map"
2
+ require "plugins/pluginator/extensions/conversions"
3
3
 
4
4
  module Pluginator::Extensions
5
5
  # Extension to check if plugin for given class name exist
@@ -1,4 +1,4 @@
1
- require_relative "plugins_map"
1
+ require "plugins/pluginator/extensions/plugins_map"
2
2
 
3
3
  module Pluginator::Extensions
4
4
  # Extension to find first plugin that answers the question with true
@@ -15,8 +15,8 @@ module Pluginator::Extensions
15
15
  def first_ask(type, method_name, *params)
16
16
  @plugins[type] or return nil
17
17
  @plugins[type].detect do |plugin|
18
- plugin.respond_to?(method_name.to_sym) &&
19
- plugin.public_send(method_name.to_sym, *params)
18
+ plugin.public_methods.map(&:to_sym).include?(method_name.to_sym) &&
19
+ plugin.send(method_name.to_sym, *params)
20
20
  end
21
21
  end
22
22
 
@@ -25,8 +25,8 @@ module Pluginator::Extensions
25
25
  def first_ask!(type, method_name, *params)
26
26
  @plugins[type] or raise Pluginator::MissingType.new(type, @plugins.keys)
27
27
  @plugins[type].detect do |plugin|
28
- plugin.respond_to?(method_name.to_sym) &&
29
- plugin.public_send(method_name, *params)
28
+ plugin.public_methods.map(&:to_sym).include?(method_name.to_sym) &&
29
+ plugin.send(method_name, *params)
30
30
  end or
31
31
  raise Pluginator::MissingPlugin.new(type, "first_ask: #{method_name}", plugins_map(type).keys)
32
32
  end
@@ -1,5 +1,5 @@
1
- require_relative "plugins_map"
2
- require_relative "conversions"
1
+ require "plugins/pluginator/extensions/plugins_map"
2
+ require "plugins/pluginator/extensions/conversions"
3
3
 
4
4
  module Pluginator::Extensions
5
5
  # Extension to find first plugin that class matches the string
@@ -1,5 +1,5 @@
1
- require_relative "plugins_map"
2
- require_relative "conversions"
1
+ require "plugins/pluginator/extensions/plugins_map"
2
+ require "plugins/pluginator/extensions/conversions"
3
3
 
4
4
  module Pluginator::Extensions
5
5
  # Extension to select plugins that class name matches the list of string
data/pluginator.gemspec CHANGED
@@ -9,10 +9,9 @@ Gem::Specification.new do |s|
9
9
  s.name = "pluginator"
10
10
  s.version = Pluginator::VERSION
11
11
  s.files = `git ls-files`.split("\n")
12
- s.required_ruby_version = ">= 1.9.2"
13
- %w{rake minitest simplecov coveralls}.each do |name|
14
- s.add_development_dependency(name)
15
- end
12
+ s.required_ruby_version = ">= 1.8.7"
13
+ s.add_development_dependency("rake")
14
+ s.add_development_dependency("minitest")
16
15
  # s.add_development_dependency("smf-gem")
17
16
  s.homepage = "https://github.com/rvm/pluginator"
18
17
  s.summary = "Rubygems plugin system using Gem.find_files."
@@ -1,11 +1,6 @@
1
1
  require 'test_helper'
2
2
  require 'pluginator/autodetect'
3
3
 
4
- module Something
5
- module Math; end
6
- module Stats; end
7
- end
8
-
9
4
  def demo_file(path)
10
5
  File.expand_path(File.join("..", "..", "..", "demo", path), __FILE__)
11
6
  end
@@ -17,7 +12,10 @@ end
17
12
  describe Pluginator::Autodetect do
18
13
  before do
19
14
  @math_files = demo_files("plugins/something/math/increase.rb", "plugins/something/math/decrease.rb")
20
- @all_files = demo_files("plugins/something/math/increase.rb", "plugins/something/math/decrease.rb", "plugins/something/stats/max.rb")
15
+ @all_files = demo_files(
16
+ "plugins/something/math/increase.rb", "plugins/something/math/decrease.rb",
17
+ "plugins/something/nested/structure/test.rb", "plugins/something/stats/max.rb"
18
+ )
21
19
  end
22
20
 
23
21
  describe "separate" do
@@ -72,7 +70,7 @@ describe Pluginator::Autodetect do
72
70
  pluginator = Pluginator::Autodetect.new("something")
73
71
  pluginator.types.must_include('stats')
74
72
  pluginator.types.must_include('math')
75
- pluginator.types.size.must_equal(2)
73
+ pluginator.types.size.must_equal(3)
76
74
  plugins = pluginator["math"].map(&:to_s)
77
75
  plugins.size.must_equal(2)
78
76
  plugins.must_include("Something::Math::Increase")
@@ -81,7 +79,7 @@ describe Pluginator::Autodetect do
81
79
  end
82
80
 
83
81
  it "loads plugins automatically for group/type" do
84
- pluginator = Pluginator::Autodetect.new("something", type: "stats")
82
+ pluginator = Pluginator::Autodetect.new("something", :type => "stats")
85
83
  pluginator.types.must_include('stats')
86
84
  pluginator.types.size.must_equal(1)
87
85
  end
@@ -94,16 +92,15 @@ describe Pluginator::Autodetect do
94
92
 
95
93
  it "hides methods" do
96
94
  pluginator = Pluginator::Autodetect.new("something")
97
- pluginator.public_methods.must_include(:register_plugin)
98
- pluginator.public_methods.wont_include(:type)
99
- pluginator.public_methods.wont_include(:load_plugins)
100
- pluginator.public_methods.wont_include(:split_file_name)
95
+ pluginator.public_methods.map(&:to_sym).must_include(:register_plugin)
96
+ pluginator.public_methods.map(&:to_sym).wont_include(:load_plugins)
97
+ pluginator.public_methods.map(&:to_sym).wont_include(:split_file_name)
98
+ pluginator.type.must_equal(nil)
101
99
  end
102
100
 
103
101
  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)
102
+ pluginator = Pluginator::Autodetect.new("something", :type => 'math')
103
+ pluginator.type.must_equal(pluginator['math'])
107
104
  end
108
105
 
109
106
  end
@@ -4,16 +4,16 @@ require 'pluginator/extendable_autodetect'
4
4
  describe Pluginator::ExtendableAutodetect do
5
5
  it "loads existing extensions - array" do
6
6
  pluginator = Pluginator::ExtendableAutodetect.new("something", :extends => [:conversions])
7
- pluginator.public_methods.must_include(:class2string)
8
- pluginator.public_methods.must_include(:string2class)
9
- pluginator.public_methods.wont_include(:plugins_map)
7
+ pluginator.public_methods.map(&:to_sym).must_include(:class2string)
8
+ pluginator.public_methods.map(&:to_sym).must_include(:string2class)
9
+ pluginator.public_methods.map(&:to_sym).wont_include(:plugins_map)
10
10
  end
11
11
 
12
12
  it "loads existing extensions - symbol" do
13
13
  pluginator = Pluginator::ExtendableAutodetect.new("something", :extends => :conversions)
14
- pluginator.public_methods.must_include(:class2string)
15
- pluginator.public_methods.must_include(:string2class)
16
- pluginator.public_methods.wont_include(:plugins_map)
14
+ pluginator.public_methods.map(&:to_sym).must_include(:class2string)
15
+ pluginator.public_methods.map(&:to_sym).must_include(:string2class)
16
+ pluginator.public_methods.map(&:to_sym).wont_include(:plugins_map)
17
17
  end
18
18
 
19
19
  it "fails to load missing extension" do
@@ -6,7 +6,8 @@ class PluginatorTest < MiniTest::Unit::TestCase
6
6
  pluginator = Pluginator.find("something")
7
7
  pluginator.types.must_include('stats')
8
8
  pluginator.types.must_include('math')
9
- pluginator.types.size.must_equal(2)
9
+ pluginator.types.must_include('nested/structure')
10
+ pluginator.types.size.must_equal(3)
10
11
  plugins = pluginator["math"].map(&:to_s)
11
12
  plugins.size.must_equal(2)
12
13
  plugins.must_include("Something::Math::Increase")
@@ -15,15 +16,23 @@ class PluginatorTest < MiniTest::Unit::TestCase
15
16
  end
16
17
 
17
18
  def test_loads_plugins_automatically_for_group_type
18
- pluginator = Pluginator.find("something", type: "stats")
19
+ pluginator = Pluginator.find("something", :type => "stats")
19
20
  pluginator.types.must_include('stats')
20
21
  pluginator.types.size.must_equal(1)
21
22
  end
22
23
 
23
24
  def test_loads_existing_extensions_symbol
24
- pluginator = Pluginator.find("something", extends: :conversions)
25
- pluginator.public_methods.must_include(:class2string)
26
- pluginator.public_methods.must_include(:string2class)
27
- pluginator.public_methods.wont_include(:plugins_map)
25
+ pluginator = Pluginator.find("something", :extends => :conversions)
26
+ pluginator.public_methods.map(&:to_sym).must_include(:class2string)
27
+ pluginator.public_methods.map(&:to_sym).must_include(:string2class)
28
+ pluginator.public_methods.map(&:to_sym).wont_include(:plugins_map)
29
+ end
30
+
31
+ def test_loads_nested_plugins
32
+ pluginator = Pluginator.find("something")
33
+ pluginator.types.must_include('nested/structure')
34
+ plugins = pluginator["nested/structure"].map(&:to_s)
35
+ plugins.size.must_equal(1)
36
+ plugins.must_include("Something::Nested::Structure::Test")
28
37
  end
29
38
  end
@@ -2,10 +2,6 @@ require 'test_helper'
2
2
  require 'plugins/pluginator/extensions/class_exist'
3
3
  require 'plugins/something/stats/max'
4
4
 
5
- module Something
6
- module Stats; end
7
- end
8
-
9
5
  class ClassExistTester
10
6
  attr_accessor :plugins
11
7
  include Pluginator::Extensions::ClassExist
@@ -2,10 +2,6 @@ require 'test_helper'
2
2
  require 'plugins/pluginator/extensions/first_ask'
3
3
  require 'plugins/something/stats/max'
4
4
 
5
- module Something
6
- module Stats; end
7
- end
8
-
9
5
  class FirstAskTester
10
6
  attr_accessor :plugins
11
7
  include Pluginator::Extensions::FirstAsk
@@ -2,10 +2,6 @@ require 'test_helper'
2
2
  require 'plugins/pluginator/extensions/first_class'
3
3
  require 'plugins/something/stats/max'
4
4
 
5
- module Something
6
- module Stats; end
7
- end
8
-
9
5
  class FirstClassTester
10
6
  attr_accessor :plugins
11
7
  include Pluginator::Extensions::FirstClass
data/test/test_helper.rb CHANGED
@@ -1,17 +1,29 @@
1
- require "coveralls"
2
- require "simplecov"
1
+ if
2
+ RUBY_VERSION == "2.0.0" # check Gemfile
3
+ then
4
+ require "coveralls"
5
+ require "simplecov"
3
6
 
4
- SimpleCov.start do
5
- formatter SimpleCov::Formatter::MultiFormatter[
6
- SimpleCov::Formatter::HTMLFormatter,
7
- Coveralls::SimpleCov::Formatter,
8
- ]
9
- command_name "Unit Tests"
10
- add_filter "/test/"
11
- add_filter "/demo/"
7
+ SimpleCov.start do
8
+ formatter SimpleCov::Formatter::MultiFormatter[
9
+ SimpleCov::Formatter::HTMLFormatter,
10
+ Coveralls::SimpleCov::Formatter,
11
+ ]
12
+ command_name "Unit Tests"
13
+ add_filter "/test/"
14
+ add_filter "/demo/"
15
+ end
16
+
17
+ Coveralls.noisy = true unless ENV['CI']
12
18
  end
13
19
 
14
- Coveralls.noisy = true unless ENV['CI']
20
+ module Something
21
+ module Math; end
22
+ module Stats; end
23
+ module Nested
24
+ module Structure; end
25
+ end
26
+ end
15
27
 
16
28
  require 'minitest/autorun'
17
29
  require 'minitest/unit'
metadata CHANGED
@@ -1,69 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pluginator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.1
4
+ version: 1.0.0
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-12-18 00:00:00.000000000 Z
11
+ date: 2013-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: minitest
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: simplecov
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
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
- - - ">="
38
+ - - '>='
67
39
  - !ruby/object:Gem::Version
68
40
  version: '0'
69
41
  description:
@@ -73,13 +45,14 @@ executables: []
73
45
  extensions: []
74
46
  extra_rdoc_files: []
75
47
  files:
76
- - ".gitignore"
77
- - ".travis.yml"
48
+ - .gitignore
49
+ - .travis.yml
78
50
  - Gemfile
79
51
  - README.md
80
52
  - Rakefile
81
53
  - demo/plugins/something/math/decrease.rb
82
54
  - demo/plugins/something/math/increase.rb
55
+ - demo/plugins/something/nested/structure/test.rb
83
56
  - demo/plugins/something/stats/max.rb
84
57
  - lib/pluginator.rb
85
58
  - lib/pluginator/autodetect.rb
@@ -100,12 +73,12 @@ files:
100
73
  - test/pluginator/group_test.rb
101
74
  - test/pluginator/name_converter_test.rb
102
75
  - test/pluginator_test.rb
103
- - test/plugins/extensions/class_exist_test.rb
104
- - test/plugins/extensions/conversions_test.rb
105
- - test/plugins/extensions/first_ask_test.rb
106
- - test/plugins/extensions/first_class_test.rb
107
- - test/plugins/extensions/matching_test.rb
108
- - test/plugins/extensions/plugins_map_test.rb
76
+ - test/plugins_test/extensions/class_exist_test.rb
77
+ - test/plugins_test/extensions/conversions_test.rb
78
+ - test/plugins_test/extensions/first_ask_test.rb
79
+ - test/plugins_test/extensions/first_class_test.rb
80
+ - test/plugins_test/extensions/matching_test.rb
81
+ - test/plugins_test/extensions/plugins_map_test.rb
109
82
  - test/test_helper.rb
110
83
  homepage: https://github.com/rvm/pluginator
111
84
  licenses: []
@@ -116,17 +89,17 @@ require_paths:
116
89
  - lib
117
90
  required_ruby_version: !ruby/object:Gem::Requirement
118
91
  requirements:
119
- - - ">="
92
+ - - '>='
120
93
  - !ruby/object:Gem::Version
121
- version: 1.9.2
94
+ version: 1.8.7
122
95
  required_rubygems_version: !ruby/object:Gem::Requirement
123
96
  requirements:
124
- - - ">="
97
+ - - '>='
125
98
  - !ruby/object:Gem::Version
126
99
  version: '0'
127
100
  requirements: []
128
101
  rubyforge_project:
129
- rubygems_version: 2.2.0
102
+ rubygems_version: 2.0.14
130
103
  signing_key:
131
104
  specification_version: 4
132
105
  summary: Rubygems plugin system using Gem.find_files.
@@ -136,10 +109,10 @@ test_files:
136
109
  - test/pluginator/group_test.rb
137
110
  - test/pluginator/name_converter_test.rb
138
111
  - test/pluginator_test.rb
139
- - test/plugins/extensions/class_exist_test.rb
140
- - test/plugins/extensions/conversions_test.rb
141
- - test/plugins/extensions/first_ask_test.rb
142
- - test/plugins/extensions/first_class_test.rb
143
- - test/plugins/extensions/matching_test.rb
144
- - test/plugins/extensions/plugins_map_test.rb
112
+ - test/plugins_test/extensions/class_exist_test.rb
113
+ - test/plugins_test/extensions/conversions_test.rb
114
+ - test/plugins_test/extensions/first_ask_test.rb
115
+ - test/plugins_test/extensions/first_class_test.rb
116
+ - test/plugins_test/extensions/matching_test.rb
117
+ - test/plugins_test/extensions/plugins_map_test.rb
145
118
  - test/test_helper.rb