public
Description: A very fast & simple Ruby web server
Homepage: http://code.macournoyer.com/thin/
Clone URL: git://github.com/macournoyer/thin.git
Search Repo:
Add very basic plugin mechanism, all gems starting with 'thin-' or 'thin_' 
will be loaded when Thin loads.
macournoyer (author)
Thu Apr 03 21:36:02 -0700 2008
commit  90b15c362fc83243ad660437a43d10f62a601332
tree    ec1016c0b79671ecda654be3cf16f35a741d59a7
parent  6cb32ec3f90457e96cdc541a387bf50e07a6ecad
...
1
 
 
2
3
4
...
1
2
3
4
5
6
0
@@ -1,4 +1,6 @@
0
 == 0.8.0 Dodgy Dentist release
0
+ * Add very basic plugin mechanism, all gems starting with 'thin-' or 'thin_' will be loaded when
0
+ Thin loads.
0
  * Allow disabling signal handling in Server with :signals => false
0
  * Make Server.new arguments more flexible, can now specify any of host, port, app or hash options.
0
  * Add --backend option to specified which backend to use, closes #55
...
47
48
49
 
 
 
 
...
47
48
49
50
51
52
53
0
@@ -47,4 +47,8 @@
0
     autoload :Rails, 'rack/adapter/rails'
0
   end
0
 end
0
+
0
+# Load plugins at last so we can reopen any stuff
0
+require 'thin/plugins'
0
+Thin::Plugins.load
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
0
@@ -1 +1,27 @@
0
+module Thin
0
+ # Very basic plugin mechanism.
0
+ # Loads all Gems which name starts with <tt>thin-</tt> or <tt>thin_</tt>.
0
+ # Just reopen classes or define all you want in your gem.
0
+ # No need for more really!
0
+ class Plugins
0
+ extend Logging
0
+
0
+ GEM_PREFIX = "thin(-|_)"
0
+
0
+ def self.gems
0
+ sdir = File.join(Gem.dir, "specifications")
0
+ Gem::SourceIndex.from_installed_gems(sdir).inject([]) do |plugins, (path, gem)|
0
+ plugins << gem.name if gem.name =~ /^#{GEM_PREFIX}/
0
+ plugins
0
+ end.uniq
0
+ end
0
+
0
+ def self.load
0
+ gems.each do |gem|
0
+ log ">> Loading #{gem} gem"
0
+ require gem
0
+ end
0
+ end
0
+ end
0
+end
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
0
@@ -1 +1,24 @@
0
+require File.dirname(__FILE__) + '/spec_helper'
0
+
0
+describe Plugins do
0
+ before do
0
+ Gem::SourceIndex.should_receive(:from_installed_gems).and_return([
0
+ ['rails-10.6.0', stub('rails-gemspec', :name => 'rails')],
0
+ ['thin-1.0', stub('thin-gemspec', :name => 'thin')],
0
+ ['thin-plugin-1.0', stub('thin-plugin-gemspec', :name => 'thin-plugin')],
0
+ ['thin-plugin-0.5', stub('thin-plugin-gemspec', :name => 'thin-plugin')],
0
+ ['thin_plugin-0.5', stub('thin_plugin-gemspec', :name => 'thin_plugin')]
0
+ ])
0
+ end
0
+
0
+ it 'should return all gems that start with thin- or thin_' do
0
+ Plugins.gems.should == ['thin-plugin', 'thin_plugin']
0
+ end
0
+
0
+ it "should load all gems" do
0
+ Plugins.should_receive(:require).with('thin-plugin')
0
+ Plugins.should_receive(:require).with('thin_plugin')
0
+ Plugins.load
0
+ end
0
+end

Comments

    No one has commented yet.