app-mgr 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/app-mgr.rb +83 -0
- metadata +55 -0
data/lib/app-mgr.rb
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
# file: app-mgr.rb
|
4
|
+
|
5
|
+
class AppMgr
|
6
|
+
def initialize()
|
7
|
+
super()
|
8
|
+
@available = {}
|
9
|
+
@running = {}
|
10
|
+
@variables = {}
|
11
|
+
end
|
12
|
+
|
13
|
+
def load(app_name, handler_name)
|
14
|
+
@available[app_name] = handler_name
|
15
|
+
"'%s' loaded" % app_name
|
16
|
+
end
|
17
|
+
|
18
|
+
def run(app_name)
|
19
|
+
if self.available? app_name then
|
20
|
+
@variables[app_name] = {}
|
21
|
+
@running[app_name] = @available[app_name].new(variables: @variables[app_name])
|
22
|
+
|
23
|
+
return "'%s' running ..." % app_name
|
24
|
+
else
|
25
|
+
return "app %s not available" % app_name
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def connect(app_name)
|
30
|
+
if running? app_name
|
31
|
+
yield(@variables[app_name])
|
32
|
+
else
|
33
|
+
return "app %s not running" % app_name
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def execute(app_name, method, params='')
|
38
|
+
[@running[app_name].method('call_' + method.gsub(/-/,'_').to_sym).call(params), 'text/xml']
|
39
|
+
end
|
40
|
+
|
41
|
+
def running?(app_name)
|
42
|
+
@running.has_key? app_name
|
43
|
+
end
|
44
|
+
|
45
|
+
def available?(app_name)
|
46
|
+
@available.has_key? app_name
|
47
|
+
end
|
48
|
+
|
49
|
+
def stop(app_name)
|
50
|
+
if @running.delete(app_name) then
|
51
|
+
return "app %s stopped" % app_name
|
52
|
+
else
|
53
|
+
return "couldn't find app %s" % app_name
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def running()
|
58
|
+
@running.keys
|
59
|
+
end
|
60
|
+
|
61
|
+
def available()
|
62
|
+
@available.keys
|
63
|
+
end
|
64
|
+
|
65
|
+
def unload(app_name)
|
66
|
+
handler_name = @available[app_name].name
|
67
|
+
@available.delete(app_name)
|
68
|
+
if handler_name then
|
69
|
+
Object.send(:remove_const, handler_name)
|
70
|
+
return "app %s unloaded" % app_name
|
71
|
+
else
|
72
|
+
return "couldn't find app %s" % app_name
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def show_public_methods(app_name)
|
77
|
+
if running? app_name
|
78
|
+
return @running[app_name].public_methods.map(&:to_s).grep(/call_/).map {|x| x.gsub(/call_/,'').gsub(/_/,'-')}.sort.join(', ')
|
79
|
+
else
|
80
|
+
return "app %s not running" % app_name
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: app-mgr
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors: []
|
7
|
+
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-08-02 00:00:00 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email:
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- lib/app-mgr.rb
|
26
|
+
has_rdoc: true
|
27
|
+
homepage:
|
28
|
+
licenses: []
|
29
|
+
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: "0"
|
40
|
+
version:
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
version:
|
47
|
+
requirements: []
|
48
|
+
|
49
|
+
rubyforge_project:
|
50
|
+
rubygems_version: 1.3.5
|
51
|
+
signing_key:
|
52
|
+
specification_version: 3
|
53
|
+
summary: app-mgr
|
54
|
+
test_files: []
|
55
|
+
|