-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplugin.rb
More file actions
38 lines (32 loc) · 768 Bytes
/
plugin.rb
File metadata and controls
38 lines (32 loc) · 768 Bytes
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
27
28
29
30
31
32
33
34
35
36
37
38
# based on code from http://eignclass.org/hiki.rb?ruby+plugins
module PluginDecorator
def def_field(*names)
class_eval do
names.each do |name|
define_method(name) do |*args|
case args.size
when 0: instance_variable_get("@#{name}")
else instance_variable_set("@#{name}", *args)
end
end
end
end
end
end
class Plugin
@plugins = []
def self.inherited(child)
Plugin.plugins << child
end
class << self
extend PluginDecorator
attr_reader :plugins
def_field :name, :author, :version, :desc
end
# Override to modify requests
def request(req_line, headers, body)
end
# Override to modify responses
def response(status_line, headers, body)
end
end