pluggability 0.2.0 → 0.3.0

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: 6657aec37785ba2a1d1b7be5f114acf4924000bc
4
- data.tar.gz: b86d76b06fa680fee6fb5288de1058340d67910d
3
+ metadata.gz: 7600ea51c42f4decce2b6402e83f70aa7b12d5c2
4
+ data.tar.gz: cee2efb2884df9d5f930d6bb284d6c8e7fce3668
5
5
  SHA512:
6
- metadata.gz: 91f428c726410e0e67fb3a5c9e83f2782e97aba1adfdbadffc38729a0bafe9c867ec18b9f75540675e8a325776a0d073ca25214e612d90015f113afdf4432aab
7
- data.tar.gz: 6b332d73c7d3abd9fb3ae481eed77931eca4760a8bb37371cb9925b5556ecc78ae4a4ec0d1fa8388da4b168ce69a3c0f0940f01725f813780d741d7b941a3b1e
6
+ metadata.gz: 7889a6316ded531e79c33b91f84537e0ecbd848e52f25eb51df7346d2b9d351758e4608f128c163d0e84aeb1672e7201dcc115f4c1af0bf8e86e4e12c9dcead6
7
+ data.tar.gz: 0dc094f630d4dcb4b6a4ca50ea311a56c83e3980fecff63fe44f58e8b67859d7f3864d9f0191885dc643ff8f6741b6cff21b2461b687388eca440962c55079d5
checksums.yaml.gz.sig CHANGED
Binary file
data/History.rdoc CHANGED
@@ -1,3 +1,8 @@
1
+ == v0.3.0 [2013-09-25] Michael Granger <ged@FaerieMUD.org>
2
+
3
+ - Add plugin exclusion patterns
4
+
5
+
1
6
  == v0.2.0 [2013-03-28] Michael Granger <ged@FaerieMUD.org>
2
7
 
3
8
  - Fix loading of grandchildren of plugins
data/Manifest.txt CHANGED
@@ -4,5 +4,5 @@ Manifest.txt
4
4
  README.rdoc
5
5
  Rakefile
6
6
  lib/pluggability.rb
7
- spec/lib/helpers.rb
7
+ spec/helpers.rb
8
8
  spec/pluggability_spec.rb
data/README.rdoc CHANGED
@@ -77,22 +77,18 @@ formats:
77
77
  def read_from_file( path ); end
78
78
  end
79
79
 
80
- When you attempt to load the 'apache' data-driver class like so:
80
+ When you attempt to load the 'apache' logreader class like so:
81
81
 
82
82
  LogReader.create( 'apache' )
83
83
 
84
84
  Pluggability searches for modules with the following names:
85
85
 
86
- 'apachedatadriver'
87
- 'apache_datadriver'
88
- 'apacheLogReader'
89
- 'apache_LogReader'
90
- 'ApacheLogReader'
91
- 'Apache_LogReader'
92
- 'apache'
93
- 'Apache'
94
-
95
- Obviously the last one will load something other than what is intended,
86
+ ApacheLogReader
87
+ apachelogreader
88
+ apache_log_reader
89
+ apache
90
+
91
+ Obviously the last one might load something other than what is intended,
96
92
  so you can also tell Pluggability that plugins should be loaded from a
97
93
  subdirectory by declaring one or more +plugin_prefixes+ in the base
98
94
  class. Each prefix will be tried (in the order they're declared) when
@@ -105,50 +101,74 @@ searching for a subclass:
105
101
 
106
102
  This will change the list that is required to:
107
103
 
108
- 'drivers/apachedatadriver'
109
- 'drivers/apache_datadriver'
110
- 'drivers/apacheLogReader'
111
- 'drivers/apache_LogReader'
112
- 'drivers/ApacheLogReader'
113
- 'drivers/Apache_LogReader'
114
- 'drivers/apache'
115
- 'drivers/Apache'
104
+ drivers/apache_logreader
105
+ drivers/apache_LogReader
106
+ drivers/apachelogreader
107
+ drivers/apacheLogReader
108
+ drivers/apache
116
109
 
117
- If you return more than one subdirectory, each of them will be tried in
110
+ If you specify more than one subdirectory, each of them will be tried in
118
111
  turn:
119
112
 
120
113
  class LogReader
121
114
  extend Pluggability
122
- plugin_prefixes 'drivers', 'datadriver'
115
+ plugin_prefixes 'drivers', 'logreader'
123
116
  end
124
117
 
125
118
  will change the search to include:
126
119
 
127
- 'drivers/apachedatadriver'
128
- 'drivers/apache_datadriver'
120
+ 'drivers/apachelogreader'
121
+ 'drivers/apache_logreader'
129
122
  'drivers/apacheLogReader'
130
123
  'drivers/apache_LogReader'
131
124
  'drivers/ApacheLogReader'
132
125
  'drivers/Apache_LogReader'
133
126
  'drivers/apache'
134
127
  'drivers/Apache'
135
- 'datadriver/apachedatadriver'
136
- 'datadriver/apache_datadriver'
137
- 'datadriver/apacheLogReader'
138
- 'datadriver/apache_LogReader'
139
- 'datadriver/ApacheLogReader'
140
- 'datadriver/Apache_LogReader'
141
- 'datadriver/apache'
142
- 'datadriver/Apache'
128
+ 'logreader/apachelogreader'
129
+ 'logreader/apache_logreader'
130
+ 'logreader/apacheLogReader'
131
+ 'logreader/apache_LogReader'
132
+ 'logreader/ApacheLogReader'
133
+ 'logreader/Apache_LogReader'
134
+ 'logreader/apache'
135
+ 'logreader/Apache'
143
136
 
144
137
  If the plugin is not found, a Pluggability::PluginError is raised, and
145
138
  the message will list all the permutations that were tried.
146
139
 
147
140
 
141
+ === Preloaded Plugins
142
+
143
+ Sometimes you don't want to wait for plugins to be loaded on demand. For
144
+ that case, Pluggability provides the load_all[rdoc-ref:Pluggability#load_all]
145
+ method. This will find all possible matches for plugin files and load
146
+ them, returning an Array of all the loaded classes:
147
+
148
+ class Template::Tag
149
+ extend Pluggability
150
+ plugin_prefixes 'tag'
151
+ end
152
+
153
+ tag_classes = Template::Tag.load_all
154
+
155
+
156
+ === Excluding Some Files
157
+
158
+ You can also prevent some files from being automatically loaded by
159
+ either create[rdoc-ref:Pluggability#create] or
160
+ load_all[rdoc-ref:Pluggability#load_all] by setting one or more exclusion
161
+ patterns:
162
+
163
+ LogReader.plugin_exclusions 'spec/*', %r{/test/}
164
+
165
+ The patterns can either be Regexps or glob Strings.
166
+
167
+
148
168
  === Logging
149
169
 
150
170
  If you need a little more insight into what's going on, Pluggability
151
- uses the "Loggability":https://rubygems.org/gems/loggability library.
171
+ uses the Loggability[https://rubygems.org/gems/loggability] library.
152
172
  Just set the log level to 'debug' and it'll explain what's going on:
153
173
 
154
174
  require 'pluggability'
@@ -166,32 +186,31 @@ Just set the log level to 'debug' and it'll explain what's going on:
166
186
 
167
187
  LogReader.create( 'ringbuffer' )
168
188
 
169
- this might generate a log that looks like:
189
+ this might generate a log that looks (something) like:
170
190
 
171
191
  [...] debug {} -- Loading derivative ringbuffer
172
192
  [...] debug {} -- Subdirs are: [""]
173
- [...] debug {} -- Path is: ["ringbuffer_datadriver",
174
- "ringbuffer_LogReader", "ringbufferdatadriver",
175
- "ringbufferLogReader", "ringbuffer"]...
176
- [...] debug {} -- Trying ringbuffer_datadriver...
177
- [...] debug {} -- No module at 'ringbuffer_datadriver', trying the
178
- next alternative: 'cannot load such file -- ringbuffer_datadriver'
193
+ [...] debug {} -- Path is: ["ringbuffer_logreader", "ringbuffer_LogReader",
194
+ "ringbufferlogreader", "ringbufferLogReader", "ringbuffer"]...
195
+ [...] debug {} -- Trying ringbuffer_logreader...
196
+ [...] debug {} -- No module at 'ringbuffer_logreader', trying the next alternative:
197
+ 'cannot load such file -- ringbuffer_logreader'
179
198
  [...] debug {} -- Trying ringbuffer_LogReader...
180
- [...] debug {} -- No module at 'ringbuffer_LogReader', trying the
181
- next alternative: 'cannot load such file -- ringbuffer_LogReader'
182
- [...] debug {} -- Trying ringbufferdatadriver...
183
- [...] debug {} -- No module at 'ringbufferdatadriver', trying the
184
- next alternative: 'cannot load such file -- ringbufferdatadriver'
199
+ [...] debug {} -- No module at 'ringbuffer_LogReader', trying the next alternative:
200
+ 'cannot load such file -- ringbuffer_LogReader'
201
+ [...] debug {} -- Trying ringbufferlogreader...
202
+ [...] debug {} -- No module at 'ringbufferlogreader', trying the next alternative:
203
+ 'cannot load such file -- ringbufferlogreader'
185
204
  [...] debug {} -- Trying ringbufferLogReader...
186
- [...] debug {} -- No module at 'ringbufferLogReader', trying the
187
- next alternative: 'cannot load such file -- ringbufferLogReader'
205
+ [...] debug {} -- No module at 'ringbufferLogReader', trying the next alternative:
206
+ 'cannot load such file -- ringbufferLogReader'
188
207
  [...] debug {} -- Trying ringbuffer...
189
- [...] debug {} -- No module at 'ringbuffer', trying the next
190
- alternative: 'cannot load such file -- ringbuffer'
208
+ [...] debug {} -- No module at 'ringbuffer', trying the next alternative:
209
+ 'cannot load such file -- ringbuffer'
191
210
  [...] debug {} -- fatals = []
192
- [...] error {} -- Couldn't find a LogReader named 'ringbuffer':
193
- tried ["ringbuffer_datadriver", "ringbuffer_LogReader",
194
- "ringbufferdatadriver", "ringbufferLogReader", "ringbuffer"]
211
+ [...] error {} -- Couldn't find a LogReader named 'ringbuffer': tried
212
+ ["ringbuffer_logreader", "ringbuffer_LogReader",
213
+ "ringbufferlogreader", "ringbufferLogReader", "ringbuffer"]
195
214
 
196
215
 
197
216
  == Installation
data/Rakefile CHANGED
@@ -5,6 +5,7 @@ require 'hoe'
5
5
  Hoe.plugin :deveiate
6
6
  Hoe.plugin :mercurial
7
7
  Hoe.plugin :signing
8
+ Hoe.plugin :bundler
8
9
 
9
10
  Hoe.plugins.delete :rubyforge
10
11
 
@@ -13,21 +14,32 @@ hoespec = Hoe.spec 'pluggability' do
13
14
  self.history_file = 'History.rdoc'
14
15
  self.extra_rdoc_files = Rake::FileList[ '*.rdoc' ]
15
16
  self.spec_extras[:rdoc_options] = ['-t', 'Pluggability Toolkit']
16
- self.spec_extras[:rdoc_options] += [ '-f', 'fivefish' ] if File.directory?( '.hg' )
17
+
18
+ # Hoops to avoid adding a formatting to the gem's spec, but still build
19
+ # with a custom formatter locally
20
+ self.spec_extras[:rdoc_options] += [ '-f', 'fivefish' ] if
21
+ File.directory?( '.hg' ) && !(ARGV.include?('gem') || ARGV.include?('release'))
17
22
 
18
23
  self.developer 'Martin Chase', 'stillflame@FaerieMUD.org'
19
24
  self.developer 'Michael Granger', 'ged@FaerieMUD.org'
20
25
 
21
- self.dependency 'loggability', '~> 0.6'
26
+ self.dependency 'loggability', '~> 0.7'
22
27
 
23
- self.dependency 'hoe-deveiate', '~> 0.2', :development
28
+ self.dependency 'hoe-deveiate', '~> 0.3', :development
29
+ self.dependency 'hoe-bundler', '~> 1.2', :development
30
+ self.dependency 'rdoc-generator-fivefish', '~> 0.1', :development
24
31
 
25
- self.spec_extras[:licenses] = ["BSD"]
32
+ self.license "BSD"
26
33
  self.hg_sign_tags = true if self.respond_to?( :hg_sign_tags= )
27
34
  self.check_history_on_release = true if self.respond_to?( :check_history_on_release= )
28
35
  self.rdoc_locations << "deveiate:/usr/local/www/public/code/#{remote_rdoc_dir}"
29
36
  end
30
37
 
38
+ task :gem do
39
+ hoespec.spec.rdoc_options.delete( '-f' )
40
+ hoespec.spec.rdoc_options.delete( 'fivefish' )
41
+ end
42
+
31
43
  ENV['VERSION'] ||= hoespec.spec.version.to_s
32
44
 
33
45
  task 'hg:precheckin' => [ :check_history, :check_manifest, :spec ]
data/lib/pluggability.rb CHANGED
@@ -12,7 +12,7 @@ module Pluggability
12
12
 
13
13
 
14
14
  # Library version
15
- VERSION = '0.2.0'
15
+ VERSION = '0.3.0'
16
16
 
17
17
 
18
18
  # An exception class for Pluggability specific errors.
@@ -23,6 +23,7 @@ module Pluggability
23
23
  ### Add the @derivatives instance variable to including classes.
24
24
  def self::extend_object( obj )
25
25
  obj.instance_variable_set( :@plugin_prefixes, [] )
26
+ obj.instance_variable_set( :@plugin_exclusions, [] )
26
27
  obj.instance_variable_set( :@derivatives, {} )
27
28
 
28
29
  Pluggability.pluggable_classes << obj
@@ -69,6 +70,50 @@ module Pluggability
69
70
  end
70
71
 
71
72
 
73
+ ### Get/set patterns which cause files in a plugin path to not be loaded. Typical
74
+ ### use case is to exclude test/spec directories:
75
+ ###
76
+ ### MyFactoryType.plugin_exclude( 'spec/**' )
77
+ ###
78
+ def plugin_exclusions( *exclusions )
79
+ @plugin_exclusions.replace( exclusions ) if !exclusions.empty?
80
+ return @plugin_exclusions
81
+ end
82
+
83
+
84
+ ### Set the plugin exclusion patterns which cause files in a plugin path to not
85
+ ### be loaded.
86
+ def plugin_exclusions=( args )
87
+ @plugin_exclusions = Array( args )
88
+ end
89
+
90
+
91
+ ### Returns +true+ if any of the #plugin_exclusions match the specified
92
+ ### +path.
93
+ def is_excluded_path?( path )
94
+ rval = self.plugin_exclusions.find do |exclusion|
95
+ case exclusion
96
+ when Regexp
97
+ path =~ exclusion
98
+ when String
99
+ flags = 0
100
+ flags &= File::FNM_EXTGLOB if defined?( File::FNM_EXTGLOB )
101
+ File.fnmatch( exclusion, path, flags )
102
+ else
103
+ Pluggability.log.warn "Don't know how to apply exclusion: %p" % [ exclusion ]
104
+ false
105
+ end
106
+ end
107
+
108
+ if rval
109
+ Pluggability.log.debug "load path %p is excluded by %p" % [ path, rval ]
110
+ return true
111
+ else
112
+ return false
113
+ end
114
+ end
115
+
116
+
72
117
  ### Returns the type name used when searching for a derivative.
73
118
  def plugin_type
74
119
  base = Pluggability.plugin_base_class( self ) or
@@ -216,7 +261,10 @@ module Pluggability
216
261
  Pluggability.log.debug " found %d matching files" % [ candidates.length ]
217
262
  next if candidates.empty?
218
263
 
219
- candidates.each {|path| require(path) }
264
+ candidates.each do |path|
265
+ next if self.is_excluded_path?( path )
266
+ require( path )
267
+ end
220
268
  end
221
269
 
222
270
  return self.derivative_classes
@@ -284,6 +332,8 @@ module Pluggability
284
332
  # module.
285
333
  subdirs.map( &:strip ).each do |subdir|
286
334
  self.make_require_path( mod_name, subdir ).each do |path|
335
+ next if self.is_excluded_path?( path )
336
+
287
337
  Pluggability.logger.debug "Trying #{path}..."
288
338
  tries << path
289
339
 
@@ -1,31 +1,23 @@
1
1
  #!/usr/bin/ruby
2
2
  # coding: utf-8
3
3
 
4
- BEGIN {
5
- require 'pathname'
6
- basedir = Pathname.new( __FILE__ ).dirname.parent
7
-
8
- libdir = basedir + "lib"
9
-
10
- $LOAD_PATH.unshift( libdir.to_s ) unless $LOAD_PATH.include?( libdir.to_s )
11
- }
12
-
13
4
  require 'rspec'
14
5
  require 'loggability/spechelpers'
15
6
  require 'pluggability'
16
7
 
17
-
18
-
19
8
  ### Mock with Rspec
20
9
  RSpec.configure do |config|
21
- ruby_version_vec = RUBY_VERSION.split('.').map {|c| c.to_i }.pack( "N*" )
22
10
 
23
- config.include( Loggability::SpecHelpers )
24
11
  config.treat_symbols_as_metadata_keys_with_true_values = true
12
+ config.run_all_when_everything_filtered = true
13
+ config.filter_run :focus
14
+ config.order = 'random'
15
+ config.mock_with( :rspec ) do |mock_config|
16
+ mock_config.syntax = :expect
17
+ end
25
18
 
26
- config.mock_with :rspec
19
+ config.include( Loggability::SpecHelpers )
27
20
  end
28
21
 
29
-
30
22
  # vim: set nosta noet ts=4 sw=4:
31
23
 
@@ -1,18 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- BEGIN {
4
- require 'pathname'
5
- basedir = Pathname.new( __FILE__ ).dirname.parent
3
+ require_relative 'helpers'
6
4
 
7
- libdir = basedir + "lib"
8
-
9
- $LOAD_PATH.unshift( basedir ) unless $LOAD_PATH.include?( basedir )
10
- $LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir )
11
- }
12
-
13
- require 'rspec'
14
5
  require 'pluggability'
15
- require 'spec/lib/helpers'
16
6
 
17
7
 
18
8
  #
@@ -39,17 +29,21 @@ class SubSubPlugin < SubPlugin; end
39
29
  #
40
30
  describe Pluggability do
41
31
 
32
+ before( :all ) do
33
+ setup_logging()
34
+ end
35
+
42
36
  before( :each ) do
43
- setup_logging( :fatal )
37
+ Plugin.plugin_exclusions = []
44
38
  end
45
39
 
46
- after( :each ) do
40
+ after( :all ) do
47
41
  reset_logging()
48
42
  end
49
43
 
50
44
 
51
45
  it "allows extended objects to declare one or more prefixes to use when requiring derviatives" do
52
- Plugin.plugin_prefixes.should == ['plugins', 'plugins/private']
46
+ expect( Plugin.plugin_prefixes ).to eq( ['plugins', 'plugins/private'] )
53
47
  end
54
48
 
55
49
 
@@ -57,19 +51,17 @@ describe Pluggability do
57
51
  context "-extended class" do
58
52
 
59
53
  it "knows about all of its derivatives" do
60
- Plugin.derivatives.keys.should include( 'sub' )
61
- Plugin.derivatives.keys.should include( 'subplugin' )
62
- Plugin.derivatives.keys.should include( 'SubPlugin' )
63
- Plugin.derivatives.keys.should include( SubPlugin )
54
+ expect( Plugin.derivatives.keys ).
55
+ to include( 'sub', 'subplugin', 'SubPlugin', SubPlugin )
64
56
  end
65
57
 
66
58
  it "returns derivatives directly if they're already loaded" do
67
59
  class AlreadyLoadedPlugin < Plugin; end
68
- Kernel.should_not_receive( :require )
69
- Plugin.create( 'alreadyloaded' ).should be_an_instance_of( AlreadyLoadedPlugin )
70
- Plugin.create( 'AlreadyLoaded' ).should be_an_instance_of( AlreadyLoadedPlugin )
71
- Plugin.create( 'AlreadyLoadedPlugin' ).should be_an_instance_of( AlreadyLoadedPlugin )
72
- Plugin.create( AlreadyLoadedPlugin ).should be_an_instance_of( AlreadyLoadedPlugin )
60
+ expect( Kernel ).to_not receive( :require )
61
+ expect( Plugin.create('alreadyloaded') ).to be_an_instance_of( AlreadyLoadedPlugin )
62
+ expect( Plugin.create('AlreadyLoaded') ).to be_an_instance_of( AlreadyLoadedPlugin )
63
+ expect( Plugin.create('AlreadyLoadedPlugin') ).to be_an_instance_of( AlreadyLoadedPlugin )
64
+ expect( Plugin.create(AlreadyLoadedPlugin) ).to be_an_instance_of( AlreadyLoadedPlugin )
73
65
  end
74
66
 
75
67
  it "filters errors that happen when creating an instance of derivatives so they " +
@@ -89,7 +81,7 @@ describe Pluggability do
89
81
  fail "Expected an exception to be raised."
90
82
  end
91
83
 
92
- exception.backtrace.first.should =~ /#{__FILE__}/
84
+ expect( exception.backtrace.first ).to match(/#{__FILE__}/)
93
85
  end
94
86
 
95
87
  it "will refuse to create an object other than one of its derivatives" do
@@ -103,14 +95,14 @@ describe Pluggability do
103
95
  it "will load new plugins from the require path if they're not loaded yet" do
104
96
  loaded_class = nil
105
97
 
106
- Plugin.should_receive( :require ).with( 'plugins/dazzle_plugin' ).and_return do |*args|
98
+ expect( Plugin ).to receive( :require ).with( 'plugins/dazzle_plugin' ).and_return do |*args|
107
99
  loaded_class = Class.new( Plugin )
108
100
  # Simulate a named class, since we're not really requiring
109
101
  Plugin.derivatives['dazzle'] = loaded_class
110
102
  true
111
103
  end
112
104
 
113
- Plugin.create( 'dazzle' ).should be_an_instance_of( loaded_class )
105
+ expect( Plugin.create('dazzle') ).to be_an_instance_of( loaded_class )
114
106
  end
115
107
 
116
108
 
@@ -118,7 +110,7 @@ describe Pluggability do
118
110
  "derivative fails" do
119
111
 
120
112
  # at least 6 -> 3 variants * 2 paths
121
- Plugin.should_receive( :require ).
113
+ expect( Plugin ).to receive( :require ).
122
114
  at_least(6).times.
123
115
  and_return {|path| raise LoadError, "path" }
124
116
 
@@ -130,7 +122,7 @@ describe Pluggability do
130
122
 
131
123
  it "will output a sensible description when a require succeeds, but it loads something unintended" do
132
124
  # at least 6 -> 3 variants * 2 paths
133
- Plugin.should_receive( :require ).and_return( true )
125
+ expect( Plugin ).to receive( :require ).and_return( true )
134
126
 
135
127
  expect {
136
128
  Plugin.create('corruscating')
@@ -142,9 +134,8 @@ describe Pluggability do
142
134
  "derivative if none of the paths work" do
143
135
 
144
136
  # at least 6 -> 3 variants * 2 paths
145
- Plugin.should_receive( :require ).at_least(6).times.and_return {|path|
146
- raise ScriptError, "error while parsing #{path}"
147
- }
137
+ expect( Plugin ).to receive( :require ).at_least(6).times.
138
+ and_raise( ScriptError.new("error while parsing path") )
148
139
 
149
140
  expect {
150
141
  Plugin.create('portable')
@@ -153,31 +144,65 @@ describe Pluggability do
153
144
 
154
145
 
155
146
  it "can preload all of its derivatives" do
156
- Gem.should_receive( :find_files ).with( 'plugins/*.rb' ).
147
+ expect( Gem ).to receive( :find_files ).with( 'plugins/*.rb' ).
148
+ and_return([ 'plugins/first.rb' ])
149
+ expect( Gem ).to receive( :find_files ).with( 'plugins/private/*.rb' ).
150
+ and_return([ 'plugins/private/second.rb', 'plugins/private/third.rb' ])
151
+
152
+ expect( Plugin ).to receive( :require ).with( 'plugins/first.rb' ).
153
+ and_return( true )
154
+ expect( Plugin ).to receive( :require ).with( 'plugins/private/second.rb' ).
155
+ and_return( true )
156
+ expect( Plugin ).to receive( :require ).with( 'plugins/private/third.rb' ).
157
+ and_return( true )
158
+
159
+ Plugin.load_all
160
+ end
161
+
162
+
163
+ it "doesn't preload derivatives whose path matches a Regexp exclusion" do
164
+ expect( Gem ).to receive( :find_files ).with( 'plugins/*.rb' ).
157
165
  and_return([ 'plugins/first.rb' ])
158
- Gem.should_receive( :find_files ).with( 'plugins/private/*.rb' ).
166
+ expect( Gem ).to receive( :find_files ).with( 'plugins/private/*.rb' ).
159
167
  and_return([ 'plugins/private/second.rb', 'plugins/private/third.rb' ])
160
168
 
161
- Plugin.should_receive( :require ).with( 'plugins/first.rb' ).
169
+ expect( Plugin ).to receive( :require ).with( 'plugins/first.rb' ).
162
170
  and_return( true )
163
- Plugin.should_receive( :require ).with( 'plugins/private/second.rb' ).
171
+ expect( Plugin ).to_not receive( :require ).with( 'plugins/private/second.rb' )
172
+ expect( Plugin ).to_not receive( :require ).with( 'plugins/private/third.rb' )
173
+
174
+ Plugin.plugin_exclusions( %r{/private} )
175
+ Plugin.load_all
176
+ end
177
+
178
+
179
+ it "doesn't preload derivatives whose path matches a glob String exclusion" do
180
+ expect( Gem ).to receive( :find_files ).with( 'plugins/*.rb' ).
181
+ and_return([ 'plugins/first.rb' ])
182
+ expect( Gem ).to receive( :find_files ).with( 'plugins/private/*.rb' ).
183
+ and_return([ 'plugins/private/second.rb', 'plugins/private/third.rb' ])
184
+
185
+ expect( Plugin ).to receive( :require ).with( 'plugins/first.rb' ).
164
186
  and_return( true )
165
- Plugin.should_receive( :require ).with( 'plugins/private/third.rb' ).
187
+ expect( Plugin ).to receive( :require ).with( 'plugins/private/second.rb' ).
166
188
  and_return( true )
189
+ expect( Plugin ).to_not receive( :require ).with( 'plugins/private/third.rb' )
167
190
 
191
+ Plugin.plugin_exclusions( '**/third.rb' )
168
192
  Plugin.load_all
169
193
  end
194
+
170
195
  end
171
196
 
172
197
 
173
198
  context "derivative of an extended class" do
174
199
 
175
200
  it "knows what type of plugin loads it" do
176
- TestingPlugin.plugin_type.should == 'Plugin'
201
+ expect( TestingPlugin.plugin_type ).to eq( 'Plugin' )
177
202
  end
178
203
 
179
204
  it "raises a PluginError if it can't figure out what type of factory loads it" do
180
- TestingPlugin.stub!( :ancestors ).and_return( [] )
205
+ allow( TestingPlugin ).to receive( :ancestors ).and_return( [] )
181
206
  expect {
182
207
  TestingPlugin.plugin_type
183
208
  }.to raise_error( Pluggability::PluginError, /couldn't find plugin base/i )
@@ -188,11 +213,11 @@ describe Pluggability do
188
213
  context "derivative of an extended class that isn't named <Something>Plugin" do
189
214
 
190
215
  it "is still creatable via its full name" do
191
- Plugin.create( 'blacksheep' ).should be_an_instance_of( BlackSheep )
216
+ expect( Plugin.create('blacksheep') ).to be_an_instance_of( BlackSheep )
192
217
  end
193
218
 
194
219
  it "is loadable via its underbarred name" do
195
- Plugin.create( 'black_sheep' ).should be_an_instance_of( BlackSheep )
220
+ expect( Plugin.create('black_sheep') ).to be_an_instance_of( BlackSheep )
196
221
  end
197
222
 
198
223
  end
@@ -201,7 +226,7 @@ describe Pluggability do
201
226
  context "derivative of an extended class in another namespace" do
202
227
 
203
228
  it "is still creatable via its derivative name" do
204
- Plugin.create( 'loadable' ).should be_an_instance_of( Test::LoadablePlugin )
229
+ expect( Plugin.create('loadable') ).to be_an_instance_of( Test::LoadablePlugin )
205
230
  end
206
231
 
207
232
  end
@@ -210,7 +235,7 @@ describe Pluggability do
210
235
  context "subclass of a derivative" do
211
236
 
212
237
  it "is still registered with the base class" do
213
- Plugin.derivatives[ 'subsub' ].should == SubSubPlugin
238
+ expect( Plugin.derivatives['subsub'] ).to eq( SubSubPlugin )
214
239
  end
215
240
 
216
241
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pluggability
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Chase
@@ -31,7 +31,7 @@ cert_chain:
31
31
  6mKCwjpegytE0oifXfF8k75A9105cBnNiMZOe1tXiqYc/exCgWvbggurzDOcRkZu
32
32
  /YSusaiDXHKU2O3Akc3htA==
33
33
  -----END CERTIFICATE-----
34
- date: 2013-03-28 00:00:00.000000000 Z
34
+ date: 2013-09-26 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: loggability
@@ -39,14 +39,14 @@ dependencies:
39
39
  requirements:
40
40
  - - ~>
41
41
  - !ruby/object:Gem::Version
42
- version: '0.6'
42
+ version: '0.7'
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - ~>
48
48
  - !ruby/object:Gem::Version
49
- version: '0.6'
49
+ version: '0.7'
50
50
  - !ruby/object:Gem::Dependency
51
51
  name: hoe-mercurial
52
52
  requirement: !ruby/object:Gem::Requirement
@@ -81,42 +81,70 @@ dependencies:
81
81
  requirements:
82
82
  - - ~>
83
83
  - !ruby/object:Gem::Version
84
- version: '3.10'
84
+ version: '4.0'
85
85
  type: :development
86
86
  prerelease: false
87
87
  version_requirements: !ruby/object:Gem::Requirement
88
88
  requirements:
89
89
  - - ~>
90
90
  - !ruby/object:Gem::Version
91
- version: '3.10'
91
+ version: '4.0'
92
92
  - !ruby/object:Gem::Dependency
93
93
  name: hoe-deveiate
94
94
  requirement: !ruby/object:Gem::Requirement
95
95
  requirements:
96
96
  - - ~>
97
97
  - !ruby/object:Gem::Version
98
- version: '0.2'
98
+ version: '0.3'
99
99
  type: :development
100
100
  prerelease: false
101
101
  version_requirements: !ruby/object:Gem::Requirement
102
102
  requirements:
103
103
  - - ~>
104
104
  - !ruby/object:Gem::Version
105
- version: '0.2'
105
+ version: '0.3'
106
+ - !ruby/object:Gem::Dependency
107
+ name: hoe-bundler
108
+ requirement: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ~>
111
+ - !ruby/object:Gem::Version
112
+ version: '1.2'
113
+ type: :development
114
+ prerelease: false
115
+ version_requirements: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ~>
118
+ - !ruby/object:Gem::Version
119
+ version: '1.2'
120
+ - !ruby/object:Gem::Dependency
121
+ name: rdoc-generator-fivefish
122
+ requirement: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ~>
125
+ - !ruby/object:Gem::Version
126
+ version: '0.1'
127
+ type: :development
128
+ prerelease: false
129
+ version_requirements: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ~>
132
+ - !ruby/object:Gem::Version
133
+ version: '0.1'
106
134
  - !ruby/object:Gem::Dependency
107
135
  name: hoe
108
136
  requirement: !ruby/object:Gem::Requirement
109
137
  requirements:
110
138
  - - ~>
111
139
  - !ruby/object:Gem::Version
112
- version: '3.5'
140
+ version: '3.7'
113
141
  type: :development
114
142
  prerelease: false
115
143
  version_requirements: !ruby/object:Gem::Requirement
116
144
  requirements:
117
145
  - - ~>
118
146
  - !ruby/object:Gem::Version
119
- version: '3.5'
147
+ version: '3.7'
120
148
  description: "Pluggability is a mixin module that turns an including class into a\nfactory
121
149
  for its derivatives, capable of searching for and loading them\nby name. This is
122
150
  useful when you have an abstract base class which\ndefines an interface and basic
@@ -154,7 +182,7 @@ files:
154
182
  - README.rdoc
155
183
  - Rakefile
156
184
  - lib/pluggability.rb
157
- - spec/lib/helpers.rb
185
+ - spec/helpers.rb
158
186
  - spec/pluggability_spec.rb
159
187
  - .gemtest
160
188
  homepage: https://bitbucket.org/ged/pluggability
@@ -165,8 +193,6 @@ post_install_message:
165
193
  rdoc_options:
166
194
  - -t
167
195
  - Pluggability Toolkit
168
- - -f
169
- - fivefish
170
196
  require_paths:
171
197
  - lib
172
198
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -181,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
181
207
  version: '0'
182
208
  requirements: []
183
209
  rubyforge_project: pluggability
184
- rubygems_version: 2.0.3
210
+ rubygems_version: 2.1.4
185
211
  signing_key:
186
212
  specification_version: 4
187
213
  summary: Pluggability is a mixin module that turns an including class into a factory
metadata.gz.sig CHANGED
Binary file