rsence-pre 2.1.0.2.pre → 2.1.0.3.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/plugins/plugin.rb +13 -4
- data/lib/plugins/plugin_plugins.rb +6 -1
- data/lib/plugins/pluginmanager.rb +58 -44
- data/lib/transporter/transporter.rb +1 -1
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.1.0.
|
1
|
+
2.1.0.3.pre
|
data/lib/plugins/plugin.rb
CHANGED
@@ -178,7 +178,15 @@ module RSence
|
|
178
178
|
@inited = true
|
179
179
|
end
|
180
180
|
end
|
181
|
-
|
181
|
+
|
182
|
+
def name_with_manager_s
|
183
|
+
if @info[:manager]
|
184
|
+
return "#{@info[:manager].to_s}:#{@name.to_s}"
|
185
|
+
else
|
186
|
+
return @name.to_s
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
182
190
|
# This method returns (or creates and returns) the entry in the session based on the name your plugin is registered as. It's advised to use this call instead of manually managing {Message#session msg#session} in most cases.
|
183
191
|
#
|
184
192
|
# Uses the first name registered for the plugin and converts it to a symbol.
|
@@ -187,7 +195,7 @@ module RSence
|
|
187
195
|
#
|
188
196
|
# @return [Hash] Plugin-specific session hash
|
189
197
|
def get_ses( msg )
|
190
|
-
name_sym =
|
198
|
+
name_sym = name_with_manager_s.to_sym
|
191
199
|
unless msg.session.has_key?( name_sym )
|
192
200
|
msg.session[ name_sym ] = {}
|
193
201
|
end
|
@@ -333,13 +341,14 @@ module RSence
|
|
333
341
|
else
|
334
342
|
default_value = 0
|
335
343
|
end
|
336
|
-
|
344
|
+
name = name_with_manager_s
|
345
|
+
ses[value_name] = HValue.new( msg, default_value, { :name => "#{name}.#{value_name}" } )
|
337
346
|
if value_properties.has_key?(:responders)
|
338
347
|
value_properties[:responders].each do |responder|
|
339
348
|
if responder.has_key?(:plugin)
|
340
349
|
responder_plugin = responder[:plugin]
|
341
350
|
else
|
342
|
-
responder_plugin =
|
351
|
+
responder_plugin = name
|
343
352
|
end
|
344
353
|
if responder.has_key?(:method)
|
345
354
|
ses[value_name].bind( responder_plugin, responder[:method] )
|
@@ -22,12 +22,16 @@ module RSence
|
|
22
22
|
# Install your sub-plugins into a directory named +plugins+ inside your plugin bundle.
|
23
23
|
module PluginPlugins
|
24
24
|
|
25
|
+
# Makes @plugin_plugins accessible
|
26
|
+
attr :plugin_plugins
|
27
|
+
|
25
28
|
# Extended {#init}, delegates calls to the sub-plugins.
|
26
29
|
def init
|
27
30
|
super
|
28
31
|
@plugin_plugins = RSence::PluginManager.new({
|
29
32
|
:plugin_paths => [ bundle_path('plugins') ],
|
30
|
-
:autoreload =>
|
33
|
+
:autoreload => false,
|
34
|
+
:name_prefix => name_with_manager_s.to_sym,
|
31
35
|
:parent_manager => @plugins
|
32
36
|
})
|
33
37
|
end
|
@@ -42,6 +46,7 @@ module RSence
|
|
42
46
|
def close
|
43
47
|
super
|
44
48
|
@plugin_plugins.delegate(:close)
|
49
|
+
@plugin_plugins.shutdown
|
45
50
|
end
|
46
51
|
|
47
52
|
# Extended {#flush}, delegates calls to the sub-plugins.
|
@@ -87,6 +87,21 @@ module RSence
|
|
87
87
|
# Calls the method +method_name+ with args +args+ of the plugin +plugin_name+.
|
88
88
|
# Returns false, if no such plugin or method exists.
|
89
89
|
def call( plugin_name, method_name, *args )
|
90
|
+
unless @name_prefix
|
91
|
+
plugin_name_s = plugin_name.to_s
|
92
|
+
if plugin_name_s.include?(':')
|
93
|
+
colon_index = plugin_name_s.index(':')
|
94
|
+
sub_manager_name = plugin_name_s[0..(colon_index-1)].to_sym
|
95
|
+
plugin_name = plugin_name_s[(colon_index+1)..-1].to_sym
|
96
|
+
if @registry.has_key?( sub_manager_name )
|
97
|
+
sub_manager = @registry[sub_manager_name]
|
98
|
+
if sub_manager.respond_to?( :plugin_plugins )
|
99
|
+
return sub_manager.plugin_plugins.call( plugin_name, method_name, *args )
|
100
|
+
end
|
101
|
+
end
|
102
|
+
return false
|
103
|
+
end
|
104
|
+
end
|
90
105
|
plugin_name = plugin_name.to_sym
|
91
106
|
if callable?( plugin_name, method_name )
|
92
107
|
begin
|
@@ -102,7 +117,7 @@ module RSence
|
|
102
117
|
elsif @deps.category?( plugin_name )
|
103
118
|
warn "Warning! Tried to call category: #{plugin_name.inpsect}"
|
104
119
|
elsif not @registry.has_key?( plugin_name )
|
105
|
-
warn "Warning! No such plugin: #{plugin_name.inspect}"
|
120
|
+
warn "Warning (#{@pluginmanager_id})! No such plugin: #{plugin_name.inspect} (tried to call #{method_name.inspect[0..100]} using args: #{args.inspect[0..100]}"
|
106
121
|
elsif not @registry[ plugin_name ].respond_to?( method_name )
|
107
122
|
warn "Warning! Plugin: #{plugin_name.inspect} does not respond to #{method_name.inspect}"
|
108
123
|
end
|
@@ -214,7 +229,11 @@ module RSence
|
|
214
229
|
# Delegates the +flush+ and +close+ methods to any
|
215
230
|
# loaded plugins, in that order.
|
216
231
|
def shutdown
|
217
|
-
@
|
232
|
+
if @parent_manager
|
233
|
+
@closed = true
|
234
|
+
else
|
235
|
+
@transporter.online = false
|
236
|
+
end
|
218
237
|
@deps.list.reverse.each do |bundle_name|
|
219
238
|
unload_bundle( bundle_name )
|
220
239
|
end
|
@@ -263,7 +282,7 @@ module RSence
|
|
263
282
|
|
264
283
|
# System version requirement.
|
265
284
|
# NOTE: Has no effect yet!
|
266
|
-
:sys_version => '>=
|
285
|
+
:sys_version => '>= 2.0.0',
|
267
286
|
|
268
287
|
# Dependency, by default the system category (built-in plugins).
|
269
288
|
# A nil ( "~" in yaml ) value means no dependencies.
|
@@ -278,7 +297,10 @@ module RSence
|
|
278
297
|
|
279
298
|
# Optional, reverse dependency. Loads before the prepended plugin(category).
|
280
299
|
# NOTE: Doesn't support packages yet!
|
281
|
-
:prepends => nil
|
300
|
+
:prepends => nil,
|
301
|
+
|
302
|
+
# Name of plugin manager, so the bundle internals know what its path is.
|
303
|
+
:manager => @name_prefix
|
282
304
|
|
283
305
|
}
|
284
306
|
|
@@ -433,6 +455,7 @@ module RSence
|
|
433
455
|
if bundle_status
|
434
456
|
(bundle_path, src_file) = bundle_status
|
435
457
|
unless disabled?( bundle_path )
|
458
|
+
# bundle_name = "#{@name_prefix.to_s}.#{bundle_name}" if @name_prefix
|
436
459
|
bundles_found.push( [bundle_path, bundle_name.to_sym, src_file] )
|
437
460
|
end
|
438
461
|
end
|
@@ -449,8 +472,10 @@ module RSence
|
|
449
472
|
end
|
450
473
|
puts "Unloading bundle: #{bundle_name.inspect}" if RSence.args[:debug]
|
451
474
|
@deps.del_item( bundle_name )
|
452
|
-
|
453
|
-
|
475
|
+
if @transporter
|
476
|
+
online_status = @transporter.online?
|
477
|
+
@transporter.online = false
|
478
|
+
end
|
454
479
|
call( bundle_name, :flush )
|
455
480
|
call( bundle_name, :close )
|
456
481
|
@registry.delete( bundle_name )
|
@@ -465,7 +490,7 @@ module RSence
|
|
465
490
|
if @info.include?( bundle_name )
|
466
491
|
@info.delete( bundle_name )
|
467
492
|
end
|
468
|
-
@transporter.online = online_status
|
493
|
+
@transporter.online = online_status if @transporter
|
469
494
|
return unload_order
|
470
495
|
end
|
471
496
|
end
|
@@ -590,6 +615,15 @@ module RSence
|
|
590
615
|
update_bundles!
|
591
616
|
end
|
592
617
|
|
618
|
+
attr_reader :transporter
|
619
|
+
attr_reader :sessions
|
620
|
+
attr_reader :autoreload
|
621
|
+
attr_reader :name_prefix
|
622
|
+
attr_reader :plugin_paths
|
623
|
+
attr_reader :parent_manager
|
624
|
+
|
625
|
+
|
626
|
+
@@pluginmanager_id = 0
|
593
627
|
# Initialize with a list of directories as plugin_paths.
|
594
628
|
# It's an array containing all plugin directories to scan.
|
595
629
|
def initialize( options )
|
@@ -603,21 +637,30 @@ module RSence
|
|
603
637
|
:parent_manager => nil
|
604
638
|
}.merge( options )
|
605
639
|
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
640
|
+
@pluginmanager_id = @@pluginmanager_id
|
641
|
+
@@pluginmanager_id += 1
|
642
|
+
|
643
|
+
@closed = false
|
644
|
+
@plugin_paths = options[:plugin_paths]
|
645
|
+
|
646
|
+
if options[:transporter]
|
647
|
+
@transporter = options[:transporter]
|
648
|
+
@sessions = options[:transporter].sessions
|
649
|
+
end
|
650
|
+
|
651
|
+
@autoreload = options[:autoreload]
|
652
|
+
@name_prefix = options[:name_prefix]
|
653
|
+
@parent_manager = options[:parent_manager]
|
611
654
|
|
612
655
|
@deps = Dependencies.new( options[:resolved_deps], options[:resolved_categories] )
|
613
656
|
|
614
|
-
puts "Loading #{@name_prefix+' ' if @name_prefix}plugins..." if RSence.args[:verbose]
|
657
|
+
puts "Loading #{@name_prefix.to_s+' ' if @name_prefix}plugins..." if RSence.args[:verbose]
|
615
658
|
init_bundles!
|
616
659
|
puts %{Plugins #{"of #{@name_prefix} " if @name_prefix}loaded.} if RSence.args[:verbose]
|
617
660
|
if @autoreload
|
618
661
|
@thr = Thread.new do
|
619
662
|
Thread.pass
|
620
|
-
|
663
|
+
until @closed
|
621
664
|
begin
|
622
665
|
update_bundles!
|
623
666
|
rescue => e
|
@@ -625,41 +668,12 @@ module RSence
|
|
625
668
|
end
|
626
669
|
sleep 3
|
627
670
|
end
|
671
|
+
puts "No longer reloading plugins of #{@name_prefix}." if RSence.args[:verbose]
|
628
672
|
end
|
629
673
|
end
|
630
674
|
|
631
675
|
end
|
632
676
|
|
633
|
-
attr_reader :transporter
|
634
|
-
attr_reader :sessions
|
635
|
-
def transporter=( transporter )
|
636
|
-
if transporter
|
637
|
-
@transporter = transporter
|
638
|
-
@sessions = transporter.sessions
|
639
|
-
end
|
640
|
-
end
|
641
|
-
|
642
|
-
attr_reader :autoreload
|
643
|
-
def autoreload=( autoreload )
|
644
|
-
@autoreload = autoreload
|
645
|
-
end
|
646
|
-
|
647
|
-
attr_reader :name_prefix
|
648
|
-
def name_prefix=( name_prefix )
|
649
|
-
@name_prefix = name_prefix
|
650
|
-
end
|
651
|
-
|
652
|
-
attr_reader :plugin_paths
|
653
|
-
def plugin_paths=( plugin_paths )
|
654
|
-
@plugin_paths = plugin_paths
|
655
|
-
end
|
656
|
-
|
657
|
-
# Optionally set a parent plugin manager to fall back on
|
658
|
-
attr_reader :parent_manager
|
659
|
-
def parent_manager=( parent_manager )
|
660
|
-
@parent_manager = parent_manager
|
661
|
-
end
|
662
|
-
|
663
677
|
end
|
664
678
|
end
|
665
679
|
|
@@ -46,7 +46,7 @@ module RSence
|
|
46
46
|
@plugins = PluginManager.new( {
|
47
47
|
:plugin_paths => RSence.config[:plugin_paths],
|
48
48
|
:transporter => self,
|
49
|
-
:
|
49
|
+
:autoreload => RSence.args[:autoupdate],
|
50
50
|
:name_prefix => false,
|
51
51
|
:resolved_deps => core_pkgs[:core],
|
52
52
|
:resolved_categories => core_pkgs
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rsence-pre
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 961916136
|
5
5
|
prerelease: true
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 1
|
9
9
|
- 0
|
10
|
-
-
|
10
|
+
- 3
|
11
11
|
- pre
|
12
|
-
version: 2.1.0.
|
12
|
+
version: 2.1.0.3.pre
|
13
13
|
platform: ruby
|
14
14
|
authors:
|
15
15
|
- Riassence Inc.
|