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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/plugg.rb +24 -8
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f758f292f23ae8fb92c6a364717f2aaa4cc01a1d
4
- data.tar.gz: f3b129b23ad44f4fff974b55a59b226130b05497
3
+ metadata.gz: ceb4462f938d690d16876d4850ddfeff28fdc6ff
4
+ data.tar.gz: 302f69f3efb7785552a42a805ba2cf5b8b1cc315
5
5
  SHA512:
6
- metadata.gz: 2584218fcb677ec964dd9cfd54b59b9a2a845f9f4d0fac7c34ef3bf348e72048064defa23d325d8eb541123dcd5a094330e76e197cbe0f7eba1c2c83393d4a5b
7
- data.tar.gz: 5a5f5b82281e12caa3d3d777b7de5fa317ccda95bd076827336d19783a78f0cbf5c951c47ef7d035e194d3ce258c8d9c756d05d73b5e484dc35b3c9f92a9da65
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.plugin_path = load_path
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, params = {})
47
- Dispatcher.instance.on(evt, params)
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 string path
62
+ # @param mixed path
63
+ # @param hash params
61
64
  # @return void
62
- def self.plugin_path=(path)
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
- Object.const_get(File.basename(f, '.rb')).new
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plugg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Nieuwoudt