plugg 0.0.2 → 0.0.3
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 +24 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ceb4462f938d690d16876d4850ddfeff28fdc6ff
|
4
|
+
data.tar.gz: 302f69f3efb7785552a42a805ba2cf5b8b1cc315
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 711b305ddc3444f19258d18513820cb2b3957689c6081e1df1c542231adbf3775552423d1a0236dd672d89e9d22b151caf55ec670bbce9ea7e5befec4dd26b4b
|
7
|
+
data.tar.gz: 3cfe47846cf54e62f5cadd0bc5726e43ff3e38576b392ec6ff2720205d5fd738e9d753ee25a1efed85daa0d4c20f986106e01369cc78bbfb620bfe535dd654d6
|
data/lib/plugg.rb
CHANGED
@@ -5,8 +5,9 @@ module Plugg
|
|
5
5
|
##
|
6
6
|
# Set the source directory to load the plugins from
|
7
7
|
#
|
8
|
+
# @param hash params
|
8
9
|
# @param mixed path
|
9
|
-
def Plugg.source(path)
|
10
|
+
def Plugg.source(path, params = {})
|
10
11
|
|
11
12
|
load_path = []
|
12
13
|
|
@@ -26,7 +27,7 @@ module Plugg
|
|
26
27
|
raise "Plugin load paths contain no valid directories"
|
27
28
|
end
|
28
29
|
|
29
|
-
Dispatcher.
|
30
|
+
Dispatcher.start(load_path, params)
|
30
31
|
end
|
31
32
|
|
32
33
|
##
|
@@ -43,8 +44,8 @@ module Plugg
|
|
43
44
|
# @param symbol evt
|
44
45
|
# @param hash params
|
45
46
|
# @return mixed
|
46
|
-
def Plugg.send(evt
|
47
|
-
Dispatcher.instance.on(evt
|
47
|
+
def Plugg.send(evt)
|
48
|
+
Dispatcher.instance.on(evt)
|
48
49
|
end
|
49
50
|
|
50
51
|
class Dispatcher
|
@@ -53,14 +54,17 @@ module Plugg
|
|
53
54
|
attr_reader :registry
|
54
55
|
|
55
56
|
@@plugin_path = []
|
57
|
+
@@params = {}
|
56
58
|
|
57
59
|
##
|
58
60
|
# Assign a path where plugins should be loaded from
|
59
61
|
#
|
60
|
-
# @param
|
62
|
+
# @param mixed path
|
63
|
+
# @param hash params
|
61
64
|
# @return void
|
62
|
-
def self.
|
65
|
+
def self.start(path, params = {})
|
63
66
|
@@plugin_path = path
|
67
|
+
@@params = params
|
64
68
|
end
|
65
69
|
|
66
70
|
##
|
@@ -80,11 +84,19 @@ module Plugg
|
|
80
84
|
require File.expand_path(f)
|
81
85
|
|
82
86
|
begin
|
87
|
+
instance = Object.const_get(File.basename(f, '.rb')).new
|
88
|
+
|
89
|
+
if instance.respond_to?(:set_params)
|
90
|
+
instance.send(:set_params, @@params)
|
91
|
+
end
|
92
|
+
|
83
93
|
@registry.push(
|
84
|
-
|
94
|
+
instance
|
85
95
|
)
|
96
|
+
|
97
|
+
instance = nil
|
86
98
|
rescue Exception => e
|
87
|
-
puts "#{f} Initialization Exception
|
99
|
+
puts "#{f} Initialization Exception: #{e}"
|
88
100
|
end
|
89
101
|
end
|
90
102
|
end
|
@@ -98,6 +110,10 @@ module Plugg
|
|
98
110
|
def on(method, *args, &block)
|
99
111
|
buffer = []
|
100
112
|
|
113
|
+
if [:initialize, :set_params].include? method
|
114
|
+
raise "#{method} should not be called this way"
|
115
|
+
end
|
116
|
+
|
101
117
|
@registry.each do |s|
|
102
118
|
if s.respond_to?(method.to_sym, include_private = false)
|
103
119
|
|