pluginfactory 1.0.7 → 1.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/.gemtest +0 -0
- data/ChangeLog +511 -212
- data/History.rdoc +46 -0
- data/Manifest.txt +8 -0
- data/README.rdoc +237 -0
- data/Rakefile +17 -347
- data/lib/pluginfactory.rb +42 -18
- data/spec/lib/helpers.rb +116 -206
- data/spec/pluginfactory_spec.rb +27 -20
- metadata +157 -97
- metadata.gz.sig +1 -2
- data/LICENSE +0 -27
- data/README +0 -200
- data/rake/191_compat.rb +0 -26
- data/rake/dependencies.rb +0 -76
- data/rake/documentation.rb +0 -115
- data/rake/helpers.rb +0 -502
- data/rake/hg.rb +0 -287
- data/rake/manual.rb +0 -787
- data/rake/packaging.rb +0 -129
- data/rake/publishing.rb +0 -348
- data/rake/style.rb +0 -62
- data/rake/svn.rb +0 -668
- data/rake/testing.rb +0 -187
- data/rake/verifytask.rb +0 -64
data/lib/pluginfactory.rb
CHANGED
@@ -23,12 +23,12 @@ class FactoryError < RuntimeError; end
|
|
23
23
|
#
|
24
24
|
# == Creation Argument Variants
|
25
25
|
#
|
26
|
-
# The +create+ class method added to your class by PluginFactory searches for your module using
|
26
|
+
# The +create+ class method added to your class by PluginFactory searches for your module using
|
27
27
|
#
|
28
28
|
# == Synopsis
|
29
|
-
#
|
29
|
+
#
|
30
30
|
# in driver.rb:
|
31
|
-
#
|
31
|
+
#
|
32
32
|
# require "PluginFactory"
|
33
33
|
#
|
34
34
|
# class Driver
|
@@ -37,50 +37,74 @@ class FactoryError < RuntimeError; end
|
|
37
37
|
# ["drivers"]
|
38
38
|
# end
|
39
39
|
# end
|
40
|
-
#
|
40
|
+
#
|
41
41
|
# in drivers/mysql.rb:
|
42
|
-
#
|
42
|
+
#
|
43
43
|
# require 'driver'
|
44
44
|
#
|
45
45
|
# class MysqlDriver < Driver
|
46
46
|
# ...implementation...
|
47
47
|
# end
|
48
|
-
#
|
48
|
+
#
|
49
49
|
# in /usr/lib/ruby/1.8/PostgresDriver.rb:
|
50
|
-
#
|
50
|
+
#
|
51
51
|
# require 'driver'
|
52
52
|
#
|
53
53
|
# class PostgresDriver < Driver
|
54
54
|
# ...implementation...
|
55
55
|
# end
|
56
|
-
#
|
56
|
+
#
|
57
57
|
# elsewhere
|
58
|
-
#
|
58
|
+
#
|
59
59
|
# require 'driver'
|
60
60
|
#
|
61
61
|
# config[:driver_type] #=> "mysql"
|
62
62
|
# driver = Driver.create( config[:driver_type] )
|
63
63
|
# driver.class #=> MysqlDriver
|
64
64
|
# pgdriver = Driver.create( "PostGresDriver" )
|
65
|
-
#
|
65
|
+
#
|
66
66
|
# == Authors
|
67
|
-
#
|
67
|
+
#
|
68
68
|
# * Martin Chase <stillflame@FaerieMUD.org>
|
69
69
|
# * Michael Granger <ged@FaerieMUD.org>
|
70
|
-
#
|
71
|
-
# :include: LICENSE
|
72
70
|
#
|
73
|
-
|
71
|
+
# == License
|
72
|
+
#
|
73
|
+
# Copyright (c) 2008-2012 Michael Granger and Martin Chase
|
74
|
+
# All rights reserved.
|
75
|
+
#
|
76
|
+
# Redistribution and use in source and binary forms, with or without
|
77
|
+
# modification, are permitted provided that the following conditions are met:
|
78
|
+
#
|
79
|
+
# * Redistributions of source code must retain the above copyright notice,
|
80
|
+
# this list of conditions and the following disclaimer.
|
81
|
+
#
|
82
|
+
# * Redistributions in binary form must reproduce the above copyright notice,
|
83
|
+
# this list of conditions and the following disclaimer in the documentation
|
84
|
+
# and/or other materials provided with the distribution.
|
85
|
+
#
|
86
|
+
# * Neither the name of the author/s, nor the names of the project's
|
87
|
+
# contributors may be used to endorse or promote products derived from this
|
88
|
+
# software without specific prior written permission.
|
74
89
|
#
|
75
|
-
#
|
90
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
91
|
+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
92
|
+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
93
|
+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
94
|
+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
95
|
+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
96
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
97
|
+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
98
|
+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
99
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
76
100
|
#
|
77
101
|
module PluginFactory
|
78
102
|
|
79
103
|
# Library version
|
80
|
-
VERSION = '1.0.
|
104
|
+
VERSION = '1.0.8'
|
81
105
|
|
82
106
|
|
83
|
-
### Logging
|
107
|
+
### Logging
|
84
108
|
@default_logger = Logger.new( $stderr )
|
85
109
|
@default_logger.level = $DEBUG ? Logger::DEBUG : Logger::WARN
|
86
110
|
|
@@ -161,7 +185,7 @@ module PluginFactory
|
|
161
185
|
base = nil
|
162
186
|
self.ancestors.each do |klass|
|
163
187
|
if klass.instance_variables.include?( :@derivatives ) ||
|
164
|
-
klass.instance_variables.include?( "@derivatives" )
|
188
|
+
klass.instance_variables.include?( "@derivatives" )
|
165
189
|
base = klass
|
166
190
|
break
|
167
191
|
end
|
data/spec/lib/helpers.rb
CHANGED
@@ -6,67 +6,26 @@ BEGIN {
|
|
6
6
|
basedir = Pathname.new( __FILE__ ).dirname.parent
|
7
7
|
|
8
8
|
libdir = basedir + "lib"
|
9
|
-
extdir = basedir + "ext"
|
10
9
|
|
11
10
|
$LOAD_PATH.unshift( libdir.to_s ) unless $LOAD_PATH.include?( libdir.to_s )
|
12
|
-
$LOAD_PATH.unshift( extdir.to_s ) unless $LOAD_PATH.include?( extdir.to_s )
|
13
11
|
}
|
14
12
|
|
15
|
-
require '
|
13
|
+
require 'rspec'
|
14
|
+
require 'pluginfactory'
|
16
15
|
|
17
|
-
### RSpec helper functions.
|
18
|
-
module PluginFactory::SpecHelpers
|
19
|
-
|
20
|
-
unless defined?( LEVEL )
|
21
|
-
LEVEL = {
|
22
|
-
:debug => Logger::DEBUG,
|
23
|
-
:info => Logger::INFO,
|
24
|
-
:warn => Logger::WARN,
|
25
|
-
:error => Logger::ERROR,
|
26
|
-
:fatal => Logger::FATAL,
|
27
|
-
}
|
28
|
-
end
|
29
|
-
|
30
|
-
###############
|
31
|
-
module_function
|
32
|
-
###############
|
33
|
-
|
34
|
-
### Reset the logging subsystem to its default state.
|
35
|
-
def reset_logging
|
36
|
-
PluginFactory.reset_logger
|
37
|
-
end
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
### Alter the output of the default log formatter to be pretty in SpecMate output
|
42
|
-
def setup_logging( level=Logger::FATAL )
|
43
|
-
|
44
|
-
# Turn symbol-style level config into Logger's expected Fixnum level
|
45
|
-
if LEVEL.key?( level )
|
46
|
-
level = LEVEL[ level ]
|
47
|
-
end
|
48
|
-
|
49
|
-
logger = Logger.new( $stderr )
|
50
|
-
PluginFactory.logger = logger
|
51
|
-
PluginFactory.logger.level = level
|
52
|
-
|
53
|
-
# Only do this when executing from a spec in TextMate
|
54
|
-
if ENV['HTML_LOGGING'] || (ENV['TM_FILENAME'] && ENV['TM_FILENAME'] =~ /_spec\.rb/)
|
55
|
-
PluginFactory.logger.formatter = HtmlLogFormatter.new( logger )
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
|
60
|
-
end
|
61
16
|
|
17
|
+
### RSpec helper functions.
|
18
|
+
module PluginFactory
|
62
19
|
|
63
|
-
|
64
|
-
|
65
|
-
|
20
|
+
# An alternate formatter for Logger instances that outputs +div+ HTML
|
21
|
+
# fragments.
|
22
|
+
# @private
|
23
|
+
class HtmlLogFormatter < Logger::Formatter
|
24
|
+
include ERB::Util # for html_escape()
|
66
25
|
|
67
|
-
|
26
|
+
# The default HTML fragment that'll be used as the template for each log message.
|
68
27
|
HTML_LOG_FORMAT = %q{
|
69
|
-
<
|
28
|
+
<div class="log-message %5$s">
|
70
29
|
<span class="log-time">%1$s.%2$06d</span>
|
71
30
|
[
|
72
31
|
<span class="log-pid">%3$d</span>
|
@@ -77,171 +36,122 @@ class HtmlLogFormatter < Logger::Formatter
|
|
77
36
|
:
|
78
37
|
<span class="log-name">%6$s</span>
|
79
38
|
<span class="log-message-text">%7$s</span>
|
80
|
-
</
|
39
|
+
</div>
|
81
40
|
}
|
82
|
-
end
|
83
|
-
|
84
|
-
### Override the logging formats with ones that generate HTML fragments
|
85
|
-
def initialize( logger, format=HTML_LOG_FORMAT ) # :notnew:
|
86
|
-
@logger = logger
|
87
|
-
@format = format
|
88
|
-
super()
|
89
|
-
end
|
90
|
-
|
91
|
-
|
92
|
-
######
|
93
|
-
public
|
94
|
-
######
|
95
|
-
|
96
|
-
# The HTML fragment that will be used as a format() string for the log
|
97
|
-
attr_accessor :format
|
98
|
-
|
99
|
-
|
100
|
-
### Return a log message composed out of the arguments formatted using the
|
101
|
-
### formatter's format string
|
102
|
-
def call( severity, time, progname, msg )
|
103
|
-
args = [
|
104
|
-
time.strftime( '%Y-%m-%d %H:%M:%S' ), # %1$s
|
105
|
-
time.usec, # %2$d
|
106
|
-
Process.pid, # %3$d
|
107
|
-
Thread.current == Thread.main ? 'main' : Thread.object_id, # %4$s
|
108
|
-
severity, # %5$s
|
109
|
-
progname, # %6$s
|
110
|
-
html_escape( msg ).gsub(/\n/, '<br />') # %7$s
|
111
|
-
]
|
112
|
-
|
113
|
-
return self.format % args
|
114
|
-
end
|
115
|
-
|
116
|
-
end
|
117
41
|
|
42
|
+
### Override the logging formats with ones that generate HTML fragments
|
43
|
+
def initialize( logger, format=HTML_LOG_FORMAT ) # :notnew:
|
44
|
+
@logger = logger
|
45
|
+
@format = format
|
46
|
+
super()
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
######
|
51
|
+
public
|
52
|
+
######
|
118
53
|
|
119
|
-
#
|
120
|
-
|
54
|
+
# The HTML fragment that will be used as a format() string for the log
|
55
|
+
attr_accessor :format
|
121
56
|
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
57
|
+
|
58
|
+
### Return a log message composed out of the arguments formatted using the
|
59
|
+
### formatter's format string
|
60
|
+
def call( severity, time, progname, msg )
|
61
|
+
args = [
|
62
|
+
time.strftime( '%Y-%m-%d %H:%M:%S' ), # %1$s
|
63
|
+
time.usec, # %2$d
|
64
|
+
Process.pid, # %3$d
|
65
|
+
Thread.current == Thread.main ? 'main' : Thread.object_id, # %4$s
|
66
|
+
severity.downcase, # %5$s
|
67
|
+
progname, # %6$s
|
68
|
+
html_escape( msg ).gsub(/\n/, '<br />') # %7$s
|
69
|
+
]
|
70
|
+
|
71
|
+
return self.format % args
|
129
72
|
end
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
73
|
+
|
74
|
+
end # class HtmlLogFormatter
|
75
|
+
|
76
|
+
|
77
|
+
### Spec helper functions
|
78
|
+
module SpecHelpers
|
79
|
+
|
80
|
+
class ArrayLogger
|
81
|
+
### Create a new ArrayLogger that will append content to +array+.
|
82
|
+
def initialize( array )
|
83
|
+
@array = array
|
84
|
+
end
|
85
|
+
|
86
|
+
### Write the specified +message+ to the array.
|
87
|
+
def write( message )
|
88
|
+
@array << message
|
89
|
+
end
|
90
|
+
|
91
|
+
### No-op -- this is here just so Logger doesn't complain
|
92
|
+
def close; end
|
93
|
+
|
94
|
+
end # class ArrayLogger
|
95
|
+
|
96
|
+
|
97
|
+
unless defined?( LEVEL )
|
98
|
+
LEVEL = {
|
99
|
+
:debug => Logger::DEBUG,
|
100
|
+
:info => Logger::INFO,
|
101
|
+
:warn => Logger::WARN,
|
102
|
+
:error => Logger::ERROR,
|
103
|
+
:fatal => Logger::FATAL,
|
104
|
+
}
|
135
105
|
end
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
message = failure.exception.message
|
145
|
-
|
146
|
-
@output.puts " <div class=\"message\"><code>#{h message}</code></div>",
|
147
|
-
" <div class=\"backtrace\"><pre>#{backtrace}</pre></div>"
|
106
|
+
|
107
|
+
###############
|
108
|
+
module_function
|
109
|
+
###############
|
110
|
+
|
111
|
+
### Make an easily-comparable version vector out of +ver+ and return it.
|
112
|
+
def vvec( ver )
|
113
|
+
return ver.split('.').collect {|char| char.to_i }.pack('N*')
|
148
114
|
end
|
149
115
|
|
150
|
-
|
151
|
-
|
116
|
+
|
117
|
+
### Reset the logging subsystem to its default state.
|
118
|
+
def reset_logging
|
119
|
+
PluginFactory.reset_logger
|
152
120
|
end
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
121
|
+
|
122
|
+
|
123
|
+
### Alter the output of the default log formatter to be pretty in SpecMate output
|
124
|
+
def setup_logging( level=Logger::FATAL )
|
125
|
+
|
126
|
+
# Turn symbol-style level config into Logger's expected Fixnum level
|
127
|
+
if LEVEL.key?( level )
|
128
|
+
level = LEVEL[ level ]
|
129
|
+
end
|
130
|
+
|
131
|
+
logger = Logger.new( $stderr )
|
132
|
+
PluginFactory.logger = logger
|
133
|
+
PluginFactory.logger.level = level
|
134
|
+
|
135
|
+
# Only do this when executing from a spec in TextMate
|
136
|
+
if ENV['HTML_LOGGING'] || (ENV['TM_FILENAME'] && ENV['TM_FILENAME'] =~ /_spec\.rb/)
|
137
|
+
Thread.current['logger-output'] = []
|
138
|
+
logdevice = ArrayLogger.new( Thread.current['logger-output'] )
|
139
|
+
PluginFactory.logger = Logger.new( logdevice )
|
140
|
+
# PluginFactory.logger.level = level
|
141
|
+
PluginFactory.logger.formatter = PluginFactory::HtmlLogFormatter.new( logger )
|
142
|
+
end
|
165
143
|
end
|
166
|
-
end
|
167
|
-
|
168
|
-
def global_styles
|
169
|
-
css = default_global_styles()
|
170
|
-
css << %Q{
|
171
|
-
/* Stuff added by #{__FILE__} */
|
172
|
-
|
173
|
-
/* Overrides */
|
174
|
-
#rspec-header {
|
175
|
-
-webkit-box-shadow: #333 0 2px 5px;
|
176
|
-
margin-bottom: 1em;
|
177
|
-
}
|
178
|
-
|
179
|
-
.example_group dt {
|
180
|
-
-webkit-box-shadow: #333 0 2px 3px;
|
181
|
-
}
|
182
|
-
|
183
|
-
/* Style for log output */
|
184
|
-
dd.log-message {
|
185
|
-
background: #eee;
|
186
|
-
padding: 0 2em;
|
187
|
-
margin: 0.2em 1em;
|
188
|
-
border-bottom: 1px dotted #999;
|
189
|
-
border-top: 1px dotted #999;
|
190
|
-
text-indent: -1em;
|
191
|
-
}
|
192
|
-
|
193
|
-
/* Parts of the message */
|
194
|
-
dd.log-message .log-time {
|
195
|
-
font-weight: bold;
|
196
|
-
}
|
197
|
-
dd.log-message .log-time:after {
|
198
|
-
content: ": ";
|
199
|
-
}
|
200
|
-
dd.log-message .log-level {
|
201
|
-
font-variant: small-caps;
|
202
|
-
border: 1px solid #ccc;
|
203
|
-
padding: 1px 2px;
|
204
|
-
}
|
205
|
-
dd.log-message .log-name {
|
206
|
-
font-size: 1.2em;
|
207
|
-
color: #1e51b2;
|
208
|
-
}
|
209
|
-
dd.log-message .log-name:before { content: "«"; }
|
210
|
-
dd.log-message .log-name:after { content: "»"; }
|
211
|
-
|
212
|
-
dd.log-message .log-message-text {
|
213
|
-
padding-left: 4px;
|
214
|
-
font-family: Monaco, "Andale Mono", "Vera Sans Mono", mono;
|
215
|
-
}
|
216
|
-
|
217
|
-
|
218
|
-
/* Distinguish levels */
|
219
|
-
dd.log-message.debug { color: #666; }
|
220
|
-
dd.log-message.info {}
|
221
|
-
|
222
|
-
dd.log-message.warn,
|
223
|
-
dd.log-message.error {
|
224
|
-
background: #ff9;
|
225
|
-
}
|
226
|
-
dd.log-message.error .log-level,
|
227
|
-
dd.log-message.error .log-message-text {
|
228
|
-
color: #900;
|
229
|
-
}
|
230
|
-
dd.log-message.fatal {
|
231
|
-
background: #900;
|
232
|
-
color: white;
|
233
|
-
font-weight: bold;
|
234
|
-
border: 0;
|
235
|
-
}
|
236
|
-
dd.log-message.fatal .log-name {
|
237
|
-
color: white;
|
238
|
-
}
|
239
|
-
}
|
240
|
-
|
241
|
-
return css
|
242
|
-
end
|
243
|
-
end # module PluginFactory::SpecHelpers
|
244
144
|
|
145
|
+
end # module SpecHelpers
|
146
|
+
|
147
|
+
end # module PluginFactory
|
148
|
+
|
149
|
+
|
150
|
+
### Mock with Rspec
|
151
|
+
RSpec.configure do |c|
|
152
|
+
c.mock_with :rspec
|
153
|
+
c.include( PluginFactory::SpecHelpers )
|
154
|
+
end
|
245
155
|
|
246
156
|
# vim: set nosta noet ts=4 sw=4:
|
247
157
|
|