plugg 0.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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/plugg.rb +128 -0
  3. metadata +45 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0988eac668e53bb82c2ddc8038fe404bc45c8c36
4
+ data.tar.gz: 5637be96140af547726975c0b2368a11e0f08f71
5
+ SHA512:
6
+ metadata.gz: 2739d5375074a4c7df289c99fd6c1a8bfb852d91c0fc1ac728385bf794458ebe610cf81554b748548a8eb8e88cb8a557d2a9c4f99a55a274830c9439269ff1c5
7
+ data.tar.gz: c332fcc6861d947749393323daec08683634039de8ffd118a0dd12d06b02be069a174e9238946f72abaafc185b3132ffbb83564dbe1935a3c9df9bc9aad76f79
@@ -0,0 +1,128 @@
1
+ require 'singleton'
2
+
3
+ module Plugg
4
+
5
+ ##
6
+ # Set the source directory to load the plugins from
7
+ #
8
+ # @param mixed path
9
+ def Plugg.source(path)
10
+
11
+ load_path = []
12
+
13
+ if !path.kind_of?(Array)
14
+ if File.directory?(path)
15
+ load_path << path
16
+ end
17
+ else
18
+ path.select! do |p|
19
+ File.directory?(p)
20
+ end
21
+
22
+ load_path.concat path
23
+ end
24
+
25
+ if load_path.empty?
26
+ raise "Plugin load paths contain no valid directories"
27
+ end
28
+
29
+ Dispatcher.plugin_path = load_path
30
+ end
31
+
32
+ ##
33
+ # Get the current registry
34
+ #
35
+ # @return array
36
+ def Plugg.registry
37
+ Dispatcher.instance.registry
38
+ end
39
+
40
+ ##
41
+ # Send an event to the plugin registry
42
+ #
43
+ # @param symbol evt
44
+ # @param hash params
45
+ # @return mixed
46
+ def Plugg.send(evt, params = {})
47
+ Dispatcher.instance.on(evt, params)
48
+ end
49
+
50
+ class Dispatcher
51
+ include Singleton
52
+
53
+ attr_reader :registry
54
+
55
+ @@plugin_path = []
56
+
57
+ ##
58
+ # Assign a path where plugins should be loaded from
59
+ #
60
+ # @param string path
61
+ # @return void
62
+ def self.plugin_path=(path)
63
+ @@plugin_path = path
64
+ end
65
+
66
+ ##
67
+ # Initialize the dispatcher and load the plugin instances
68
+ #
69
+ # @return void
70
+ def initialize
71
+ @registry = []
72
+
73
+ @@plugin_path.each do |path|
74
+ if path[-1] == '/'
75
+ path.chop!
76
+ end
77
+
78
+ Dir["#{path}/*.rb"].each do |f|
79
+
80
+ require File.expand_path(f)
81
+
82
+ begin
83
+ @registry.push(
84
+ Object.const_get(File.basename(f, '.rb')).new
85
+ )
86
+ rescue Exception => e
87
+ puts "#{f} Initialization Exception."
88
+ end
89
+ end
90
+ end
91
+ end
92
+
93
+ ##
94
+ # Loop through all services and fire off the supported messages
95
+ #
96
+ # @param string method
97
+ # @return void
98
+ def on(method, *args, &block)
99
+ buffer = []
100
+
101
+ @registry.each do |s|
102
+ if s.respond_to?(method.to_sym, include_private = false)
103
+
104
+ start = Time.now
105
+ response = nil
106
+
107
+ begin
108
+ if s.method(method.to_sym).arity == 0
109
+ response = s.send(method, &block)
110
+ else
111
+ response = s.send(method, *args, &block)
112
+ end
113
+ rescue Exception => e
114
+ response = e
115
+ end
116
+
117
+ buffer << {
118
+ :plugin => s.to_s,
119
+ :return => response,
120
+ :timing => (Time.now - start) * 1000
121
+ }
122
+ end
123
+ end
124
+
125
+ buffer
126
+ end
127
+ end
128
+ end
metadata ADDED
@@ -0,0 +1,45 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: plugg
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sean Nieuwoudt
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-03 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Plugg allows you to easily extend your application by providing you with
14
+ a bolt-on plugin framework
15
+ email: sean@wixelhq.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/plugg.rb
21
+ homepage: https://wixelhq.com
22
+ licenses:
23
+ - GPL2
24
+ metadata: {}
25
+ post_install_message:
26
+ rdoc_options: []
27
+ require_paths:
28
+ - lib
29
+ required_ruby_version: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ required_rubygems_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 2.4.5
42
+ signing_key:
43
+ specification_version: 4
44
+ summary: Plugg is an independent plugin creation framework and DSL
45
+ test_files: []