plugg 0.0.4 → 0.0.5
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 +4 -4
- data/lib/plugg.rb +64 -38
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2166868234da45a8933c515af1e93bde8963d47a
|
4
|
+
data.tar.gz: 970f8abd1ed3e35f4182514122704f8d12341c0f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e4e566793a997bfc4c8726b680e2831d02e6361c2e1590301745bc5bc4612421efecf55565bf63d086bdfdefa9cfbc3f824dc523d3c2ceb263cf6c41091a34c0
|
7
|
+
data.tar.gz: cf9de28d3d51a77bd671e9bc187e6a451c6f9683d9ab2b23d764daf3f82111799b0c60983d775ed5481693929b99a22cf04893ba5539d25f49393d5f9c836081
|
data/lib/plugg.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'singleton'
|
2
|
+
require 'timeout'
|
2
3
|
|
3
4
|
module Plugg
|
4
|
-
|
5
5
|
##
|
6
6
|
# Set the source directory to load the plugins from
|
7
7
|
#
|
@@ -24,10 +24,18 @@ module Plugg
|
|
24
24
|
end
|
25
25
|
|
26
26
|
if load_path.empty?
|
27
|
-
raise
|
27
|
+
raise 'Unable to locate plugins in the provided load path'
|
28
28
|
end
|
29
29
|
|
30
|
-
Dispatcher.start(load_path, params)
|
30
|
+
Dispatcher.instance.start(load_path, params)
|
31
|
+
end
|
32
|
+
|
33
|
+
##
|
34
|
+
# Set the dispatch plugin timeout value
|
35
|
+
#
|
36
|
+
# @param integer t
|
37
|
+
def Plugg.timeout(t = 30)
|
38
|
+
Dispatcher.instance.set_timeout(t)
|
31
39
|
end
|
32
40
|
|
33
41
|
##
|
@@ -45,16 +53,16 @@ module Plugg
|
|
45
53
|
# @param hash params
|
46
54
|
# @return mixed
|
47
55
|
def Plugg.send(evt, params = {})
|
48
|
-
Dispatcher.instance.on(evt, params)
|
56
|
+
Dispatcher.instance.on(evt.to_sym, params)
|
49
57
|
end
|
50
58
|
|
59
|
+
private
|
60
|
+
|
51
61
|
class Dispatcher
|
52
62
|
include Singleton
|
53
63
|
|
54
64
|
attr_reader :registry
|
55
|
-
|
56
|
-
@@plugin_path = []
|
57
|
-
@@params = {}
|
65
|
+
attr_accessor :timeout
|
58
66
|
|
59
67
|
##
|
60
68
|
# Assign a path where plugins should be loaded from
|
@@ -62,19 +70,10 @@ module Plugg
|
|
62
70
|
# @param mixed path
|
63
71
|
# @param hash params
|
64
72
|
# @return void
|
65
|
-
def
|
66
|
-
@@plugin_path = path
|
67
|
-
@@params = params
|
68
|
-
end
|
69
|
-
|
70
|
-
##
|
71
|
-
# Initialize the dispatcher and load the plugin instances
|
72
|
-
#
|
73
|
-
# @return void
|
74
|
-
def initialize
|
73
|
+
def start(paths, params = {})
|
75
74
|
@registry = []
|
76
75
|
|
77
|
-
|
76
|
+
paths.each do |path|
|
78
77
|
if path[-1] == '/'
|
79
78
|
path.chop!
|
80
79
|
end
|
@@ -86,22 +85,37 @@ module Plugg
|
|
86
85
|
begin
|
87
86
|
instance = Object.const_get(File.basename(f, '.rb')).new
|
88
87
|
|
89
|
-
if instance.respond_to?(:
|
90
|
-
instance.send(:
|
88
|
+
if instance.respond_to?(:setup)
|
89
|
+
instance.send(:setup, params)
|
91
90
|
end
|
92
91
|
|
93
|
-
@registry.push(
|
94
|
-
instance
|
95
|
-
)
|
92
|
+
@registry.push(instance)
|
96
93
|
|
97
94
|
instance = nil
|
98
95
|
rescue Exception => e
|
99
|
-
puts "#{f} Initialization Exception: #{e}"
|
96
|
+
puts "#{f} Plugg Initialization Exception: #{e}"
|
100
97
|
end
|
101
98
|
end
|
102
99
|
end
|
103
100
|
end
|
104
101
|
|
102
|
+
##
|
103
|
+
# Set the the thread execution timeout
|
104
|
+
#
|
105
|
+
# @param integer t
|
106
|
+
# @return void
|
107
|
+
def set_timeout(t)
|
108
|
+
@timeout = t
|
109
|
+
end
|
110
|
+
|
111
|
+
##
|
112
|
+
# Initialize the dispatcher instance
|
113
|
+
#
|
114
|
+
# @return void
|
115
|
+
def initialize
|
116
|
+
@timeout = 30
|
117
|
+
end
|
118
|
+
|
105
119
|
##
|
106
120
|
# Loop through all services and fire off the supported messages
|
107
121
|
#
|
@@ -110,34 +124,46 @@ module Plugg
|
|
110
124
|
def on(method, *args, &block)
|
111
125
|
buffer = []
|
112
126
|
|
113
|
-
if [:initialize, :
|
114
|
-
raise "#{method} should not be called
|
127
|
+
if [:initialize, :setup].include? method
|
128
|
+
raise "#{method} should not be called directly"
|
115
129
|
end
|
116
130
|
|
131
|
+
threads = []
|
132
|
+
|
117
133
|
@registry.each do |s|
|
118
134
|
if s.respond_to?(method.to_sym, false)
|
119
135
|
|
120
|
-
|
121
|
-
response = nil
|
136
|
+
start_time = Time.now
|
122
137
|
|
123
138
|
begin
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
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
|
+
}
|
128
157
|
end
|
129
158
|
rescue Exception => e
|
130
159
|
response = e
|
160
|
+
status = false
|
131
161
|
end
|
132
|
-
|
133
|
-
buffer << {
|
134
|
-
:plugin => s.to_s,
|
135
|
-
:return => response,
|
136
|
-
:timing => (Time.now - start) * 1000
|
137
|
-
}
|
138
162
|
end
|
139
163
|
end
|
140
164
|
|
165
|
+
threads.map(&:join)
|
166
|
+
|
141
167
|
buffer
|
142
168
|
end
|
143
169
|
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: 0.0.
|
4
|
+
version: 0.0.5
|
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: 2017-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -60,7 +60,7 @@ files:
|
|
60
60
|
- lib/plugg.rb
|
61
61
|
homepage: https://wixelhq.com
|
62
62
|
licenses:
|
63
|
-
-
|
63
|
+
- GPL-2.0
|
64
64
|
metadata: {}
|
65
65
|
post_install_message:
|
66
66
|
rdoc_options: []
|
@@ -78,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
78
|
version: '0'
|
79
79
|
requirements: []
|
80
80
|
rubyforge_project:
|
81
|
-
rubygems_version: 2.
|
81
|
+
rubygems_version: 2.6.11
|
82
82
|
signing_key:
|
83
83
|
specification_version: 4
|
84
84
|
summary: Plugg is an independent plugin creation framework and DSL
|