pluginator 1.0.0 → 1.0.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
- ---
2
- SHA1:
3
- metadata.gz: b70400f4d804c2f5916e9e68056db1287345f508
4
- data.tar.gz: 5ebb958035ec8e95699a3ce44b86327acd8276c4
5
- SHA512:
6
- metadata.gz: 6c51706e34d5d00c1e60406cb5c897d4e726159ee368aa7929ecd8cf2a08c911e5c05e79acc603e8eedcd63a21e2491e30e07320ae423e102e2a1d4e3335ce3d
7
- data.tar.gz: 3f19a9c45614acaa882c289155cf0686970fbeda14390483f526573fcf87c61b4baf9547c9e15ccd5c7c1b2cf11662859d067ec8bce792154dd9e048cde0986d
1
+ ---
2
+ SHA512:
3
+ data.tar.gz: 8978e772d2d9611da6f0237fceff4349308c1b882d9a677a1b7a98f03671e1b9c2d130656c9283027bddcc4e28a03ac092fdb27e020ef04deb4eaf4aa650c36a
4
+ metadata.gz: 9d61123257259cdd06fa87e89063aebb068bef8611ba0bdb2838e93580dec662e9a79423c42f832781e54a8000d061aa408fa683e5703d7ab1794aa9967470c9
5
+ SHA1:
6
+ data.tar.gz: 5681dfc0f9982ecb005834e0aa96fa832895bdda
7
+ metadata.gz: 3e87d0ef8aa32713ffc2e72eae88224c5f1cf227
data/Changelog.md ADDED
@@ -0,0 +1,12 @@
1
+ # Changelog
2
+
3
+ ## 1.0.1
4
+ date: 2013-12-25
5
+
6
+ - divide first_ask code into smaller methods, remove duplication
7
+ - add conversiosn helper class2name
8
+
9
+ ## 1.0.0
10
+ date: 2013-12-20
11
+
12
+ - Stable version released
@@ -1,4 +1,4 @@
1
1
  module Pluginator
2
2
  # Version of Pluginator
3
- VERSION = "1.0.0"
3
+ VERSION = "1.0.1"
4
4
  end
@@ -12,5 +12,10 @@ module Pluginator::Extensions
12
12
  str.to_s.capitalize.gsub(/_(.)/){ $1.upcase }
13
13
  end
14
14
 
15
+ # gets class name last part
16
+ def class2name(klass)
17
+ klass.name.split('::').last
18
+ end
19
+
15
20
  end
16
21
  end
@@ -14,21 +14,29 @@ module Pluginator::Extensions
14
14
  # @return The first plugin that method call returns true
15
15
  def first_ask(type, method_name, *params)
16
16
  @plugins[type] or return nil
17
- @plugins[type].detect do |plugin|
18
- plugin.public_methods.map(&:to_sym).include?(method_name.to_sym) &&
19
- plugin.send(method_name.to_sym, *params)
20
- end
17
+ try_to_find(type, method_name, params)
21
18
  end
22
19
 
23
20
  # Call a method on plugin and return first one that returns `true`.
24
21
  # Behaves like `first_ask` but throws exceptions if can not find anything.
25
22
  def first_ask!(type, method_name, *params)
26
23
  @plugins[type] or raise Pluginator::MissingType.new(type, @plugins.keys)
24
+ try_to_find(type, method_name, params) or
25
+ raise Pluginator::MissingPlugin.new(type, "first_ask: #{method_name}", plugins_map(type).keys)
26
+ end
27
+
28
+ private
29
+
30
+ def try_to_find(type, method_name, params)
27
31
  @plugins[type].detect do |plugin|
28
- plugin.public_methods.map(&:to_sym).include?(method_name.to_sym) &&
29
- plugin.send(method_name, *params)
30
- end or
31
- raise Pluginator::MissingPlugin.new(type, "first_ask: #{method_name}", plugins_map(type).keys)
32
+ has_public_method?(plugin, method_name) &&
33
+ plugin.send(method_name.to_sym, *params)
34
+ end
35
+ end
36
+
37
+ # need to use this trick because of old rubies support
38
+ def has_public_method?(plugin, method_name)
39
+ plugin.public_methods.map(&:to_sym).include?(method_name.to_sym)
32
40
  end
33
41
 
34
42
  end
@@ -1,6 +1,10 @@
1
+ require "plugins/pluginator/extensions/conversions"
2
+
1
3
  module Pluginator::Extensions
2
4
  # extend Pluginator with map of plugins: name => klass
3
5
  module PluginsMap
6
+ include Conversions
7
+
4
8
  # provide extra map of plugins with symbolized names as keys
5
9
  #
6
10
  # @param type [String] name of type to generate the map for
@@ -8,7 +12,7 @@ module Pluginator::Extensions
8
12
  def plugins_map( type )
9
13
  @plugins_map ||= {}
10
14
  type = type.to_s
11
- @plugins_map[type] ||= Hash[ @plugins[type].map{|plugin| [plugin.name.split('::').last, plugin] } ]
15
+ @plugins_map[type] ||= Hash[ @plugins[type].map{|plugin| [class2name(plugin), plugin] } ]
12
16
  end
13
17
  end
14
18
  end
metadata CHANGED
@@ -1,52 +1,48 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: pluginator
3
- version: !ruby/object:Gem::Version
4
- version: 1.0.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.1
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - Michal Papis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-12-20 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
11
+
12
+ date: 2013-12-25 00:00:00 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
14
15
  name: rake
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - '>='
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
21
16
  prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - '>='
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: minitest
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - '>='
32
- - !ruby/object:Gem::Version
33
- version: '0'
17
+ requirement: &id001 !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - &id002
20
+ - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
34
23
  type: :development
24
+ version_requirements: *id001
25
+ - !ruby/object:Gem::Dependency
26
+ name: minitest
35
27
  prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - '>='
39
- - !ruby/object:Gem::Version
40
- version: '0'
28
+ requirement: &id003 !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - *id002
31
+ type: :development
32
+ version_requirements: *id003
41
33
  description:
42
- email:
34
+ email:
43
35
  - mpapis@gmail.com
44
36
  executables: []
37
+
45
38
  extensions: []
39
+
46
40
  extra_rdoc_files: []
47
- files:
41
+
42
+ files:
48
43
  - .gitignore
49
44
  - .travis.yml
45
+ - Changelog.md
50
46
  - Gemfile
51
47
  - README.md
52
48
  - Rakefile
@@ -82,28 +78,30 @@ files:
82
78
  - test/test_helper.rb
83
79
  homepage: https://github.com/rvm/pluginator
84
80
  licenses: []
81
+
85
82
  metadata: {}
83
+
86
84
  post_install_message:
87
85
  rdoc_options: []
88
- require_paths:
86
+
87
+ require_paths:
89
88
  - lib
90
- required_ruby_version: !ruby/object:Gem::Requirement
91
- requirements:
92
- - - '>='
93
- - !ruby/object:Gem::Version
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
94
93
  version: 1.8.7
95
- required_rubygems_version: !ruby/object:Gem::Requirement
96
- requirements:
97
- - - '>='
98
- - !ruby/object:Gem::Version
99
- version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - *id002
100
97
  requirements: []
98
+
101
99
  rubyforge_project:
102
100
  rubygems_version: 2.0.14
103
101
  signing_key:
104
102
  specification_version: 4
105
103
  summary: Rubygems plugin system using Gem.find_files.
106
- test_files:
104
+ test_files:
107
105
  - test/pluginator/autodetect_test.rb
108
106
  - test/pluginator/extendable_autodetect_test.rb
109
107
  - test/pluginator/group_test.rb