plugg 0.0.5 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/lib/plugg.rb +82 -36
- metadata +9 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7b0bf38d3e6aaddc835e122ca4186a378ed7a02bd32e13317dfa94165f39bd99
|
4
|
+
data.tar.gz: bcea21911dc7bce085bb53788c027f6ac95d7233985dc19626316bfec316931f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9052c09eb89ea8314d619d1eb377e11f26ebd533e7bdcbee931caeac7638a54cca6039cbe4a38efe445186ceb249915a34a8a6fd442e02ee4b38be745dd54da
|
7
|
+
data.tar.gz: 6ca5ca8dc2bfb25ab6bdcbc98b0e6efd2570976da0c3912d90ed98b2fb551a7fd5cfc7dbbae3512462b0e05f2e4bb3c09f582f2b04eada3ae6fd27e6dc859d85
|
data/lib/plugg.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
require 'singleton'
|
2
2
|
require 'timeout'
|
3
|
+
require 'ostruct'
|
3
4
|
|
4
5
|
module Plugg
|
5
6
|
##
|
6
|
-
# Set the source directory to load the plugins from
|
7
|
+
# Set the source directory to load the plugins & dependencies from
|
7
8
|
#
|
8
9
|
# @param hash params
|
9
10
|
# @param mixed path
|
@@ -24,7 +25,7 @@ module Plugg
|
|
24
25
|
end
|
25
26
|
|
26
27
|
if load_path.empty?
|
27
|
-
raise 'Unable to locate plugins in the provided load
|
28
|
+
raise 'Unable to locate plugins in the provided load paths'
|
28
29
|
end
|
29
30
|
|
30
31
|
Dispatcher.instance.start(load_path, params)
|
@@ -58,6 +59,58 @@ module Plugg
|
|
58
59
|
|
59
60
|
private
|
60
61
|
|
62
|
+
class DispatchResponder
|
63
|
+
attr_reader :plugin
|
64
|
+
attr_reader :meta
|
65
|
+
|
66
|
+
def initialize(plugin = nil)
|
67
|
+
@meta = OpenStruct.new
|
68
|
+
|
69
|
+
@meta.start_time = Time.now
|
70
|
+
@meta.plugin = plugin
|
71
|
+
@meta.response = nil
|
72
|
+
@meta.runtime = nil
|
73
|
+
@meta.error = nil
|
74
|
+
end
|
75
|
+
|
76
|
+
def trap(timeout = 5)
|
77
|
+
Timeout::timeout(timeout) {
|
78
|
+
begin
|
79
|
+
@meta.response = yield
|
80
|
+
rescue Exception => e
|
81
|
+
@meta.error = e
|
82
|
+
end
|
83
|
+
}
|
84
|
+
|
85
|
+
@meta.runtime = (Time.now - @start_time) * 1000
|
86
|
+
end
|
87
|
+
|
88
|
+
def finalize
|
89
|
+
if @meta.plugin.respond_to?(:after)
|
90
|
+
@meta.plugin.send(:after)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def ok?
|
95
|
+
@meta.error.nil?
|
96
|
+
end
|
97
|
+
|
98
|
+
def error
|
99
|
+
@meta.error
|
100
|
+
end
|
101
|
+
|
102
|
+
def to_h
|
103
|
+
defaults = {
|
104
|
+
plugin: @meta.plugin.to_s,
|
105
|
+
runtime: @meta.runtime,
|
106
|
+
response: @meta.error,
|
107
|
+
success: ok?
|
108
|
+
}
|
109
|
+
|
110
|
+
defaults
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
61
114
|
class Dispatcher
|
62
115
|
include Singleton
|
63
116
|
|
@@ -85,13 +138,18 @@ module Plugg
|
|
85
138
|
begin
|
86
139
|
instance = Object.const_get(File.basename(f, '.rb')).new
|
87
140
|
|
141
|
+
# `before` event callback
|
142
|
+
if instance.respond_to?(:before)
|
143
|
+
instance.send(:before)
|
144
|
+
end
|
145
|
+
|
146
|
+
# `setup` method
|
88
147
|
if instance.respond_to?(:setup)
|
89
148
|
instance.send(:setup, params)
|
90
149
|
end
|
91
150
|
|
92
|
-
|
93
|
-
|
94
|
-
instance = nil
|
151
|
+
@registry.push(instance)
|
152
|
+
|
95
153
|
rescue Exception => e
|
96
154
|
puts "#{f} Plugg Initialization Exception: #{e}"
|
97
155
|
end
|
@@ -109,11 +167,11 @@ module Plugg
|
|
109
167
|
end
|
110
168
|
|
111
169
|
##
|
112
|
-
# Initialize the dispatcher instance
|
170
|
+
# Initialize the dispatcher instance with a default timeout of 5s
|
113
171
|
#
|
114
172
|
# @return void
|
115
173
|
def initialize
|
116
|
-
@timeout =
|
174
|
+
@timeout = 5
|
117
175
|
end
|
118
176
|
|
119
177
|
##
|
@@ -122,42 +180,30 @@ module Plugg
|
|
122
180
|
# @param string method
|
123
181
|
# @return void
|
124
182
|
def on(method, *args, &block)
|
125
|
-
buffer = []
|
126
183
|
|
127
|
-
if [:initialize, :setup].include? method
|
184
|
+
if [:initialize, :before, :setup, :after].include? method
|
128
185
|
raise "#{method} should not be called directly"
|
129
186
|
end
|
130
187
|
|
131
|
-
|
188
|
+
buffer = [] # Container for the response buffer
|
189
|
+
threads = [] # Container for the execution threads
|
132
190
|
|
133
191
|
@registry.each do |s|
|
134
|
-
|
192
|
+
if s.respond_to?(method.to_sym, false)
|
193
|
+
threads << Thread.new do
|
194
|
+
responder = DispatchResponder.new(s)
|
195
|
+
|
196
|
+
responder.trap(@timeout) do
|
197
|
+
if s.method(method.to_sym).arity == 0
|
198
|
+
s.send(method, &block)
|
199
|
+
else
|
200
|
+
s.send(method, *args, &block)
|
201
|
+
end
|
202
|
+
end
|
135
203
|
|
136
|
-
|
204
|
+
responder.finalize
|
137
205
|
|
138
|
-
|
139
|
-
threads << Thread.new do
|
140
|
-
status = true
|
141
|
-
response = nil
|
142
|
-
|
143
|
-
Timeout::timeout(@timeout) {
|
144
|
-
if s.method(method.to_sym).arity == 0
|
145
|
-
response = s.send(method, &block)
|
146
|
-
else
|
147
|
-
response = s.send(method, *args, &block)
|
148
|
-
end
|
149
|
-
}
|
150
|
-
|
151
|
-
buffer << {
|
152
|
-
plugin: s.to_s,
|
153
|
-
return: response,
|
154
|
-
timing: (Time.now - start_time) * 1000,
|
155
|
-
success: status
|
156
|
-
}
|
157
|
-
end
|
158
|
-
rescue Exception => e
|
159
|
-
response = e
|
160
|
-
status = false
|
206
|
+
buffer << responder.to_h
|
161
207
|
end
|
162
208
|
end
|
163
209
|
end
|
@@ -167,4 +213,4 @@ module Plugg
|
|
167
213
|
buffer
|
168
214
|
end
|
169
215
|
end
|
170
|
-
end
|
216
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plugg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Nieuwoudt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -36,29 +36,23 @@ dependencies:
|
|
36
36
|
requirements:
|
37
37
|
- - "~>"
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: '
|
40
|
-
- - ">="
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
version: 10.4.2
|
39
|
+
version: '13.0'
|
43
40
|
type: :development
|
44
41
|
prerelease: false
|
45
42
|
version_requirements: !ruby/object:Gem::Requirement
|
46
43
|
requirements:
|
47
44
|
- - "~>"
|
48
45
|
- !ruby/object:Gem::Version
|
49
|
-
version: '
|
50
|
-
- - ">="
|
51
|
-
- !ruby/object:Gem::Version
|
52
|
-
version: 10.4.2
|
46
|
+
version: '13.0'
|
53
47
|
description: Plugg allows you to easily extend your application by providing you with
|
54
|
-
a
|
55
|
-
email: sean@
|
48
|
+
a plug and play plugin framework
|
49
|
+
email: sean@isean.co.za
|
56
50
|
executables: []
|
57
51
|
extensions: []
|
58
52
|
extra_rdoc_files: []
|
59
53
|
files:
|
60
54
|
- lib/plugg.rb
|
61
|
-
homepage: https://
|
55
|
+
homepage: https://github.com/sn/plugg
|
62
56
|
licenses:
|
63
57
|
- GPL-2.0
|
64
58
|
metadata: {}
|
@@ -77,9 +71,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
71
|
- !ruby/object:Gem::Version
|
78
72
|
version: '0'
|
79
73
|
requirements: []
|
80
|
-
|
81
|
-
rubygems_version: 2.6.11
|
74
|
+
rubygems_version: 3.1.4
|
82
75
|
signing_key:
|
83
76
|
specification_version: 4
|
84
|
-
summary: Plugg is an
|
77
|
+
summary: Plugg is a an asynchronous DSL for creating performant plugins
|
85
78
|
test_files: []
|