app-mgr 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/app-mgr.rb +28 -29
  2. metadata +2 -2
@@ -1,53 +1,48 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
3
  # file: app-mgr.rb
4
-
5
4
  class AppMgr
6
5
  def initialize()
7
6
  super()
8
- @available = {}
9
- @running = {}
10
- @variables = {}
7
+ @app = {}
11
8
  end
12
9
 
13
- def load(app_name, handler_name)
14
- @available[app_name] = handler_name
15
- "'%s' loaded" % app_name
10
+ def load(opt={})
11
+ o = {name: '', object: nil, config: {}, public: {}}.merge!(opt)
12
+
13
+ key, name = o.shift
14
+ @app[name] = o
15
+ "'%s' loaded" % name
16
16
  end
17
17
 
18
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])
19
+ app = @app[app_name]
20
+ if app then
21
+ options = {public: app[:public]}
22
+ options[:config] = app[:config] unless app[:config].empty?
23
+ app[:running] = app[:object].new(options)
22
24
 
23
25
  return "'%s' running ..." % app_name
24
26
  else
25
27
  return "app %s not available" % app_name
26
- end
28
+ end
27
29
  end
28
30
 
29
31
  def connect(app_name)
30
- if running? app_name
31
- yield(@variables[app_name])
32
+ app = @app[app_name]
33
+ if app and app[:running] then
34
+ yield(app[:public])
32
35
  else
33
36
  return "app %s not running" % app_name
34
37
  end
35
38
  end
36
39
 
37
40
  def execute(app_name, method, params='')
38
- @running[app_name].method('call_' + method.gsub(/-/,'_').to_sym).call(params)
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
41
+ [@app[app_name][:running].method('call_' + method.gsub(/-/,'_').to_sym).call(params)]
47
42
  end
48
43
 
49
44
  def stop(app_name)
50
- if @running.delete(app_name) then
45
+ if @app[app_name].delete(:running) then
51
46
  return "app %s stopped" % app_name
52
47
  else
53
48
  return "couldn't find app %s" % app_name
@@ -55,18 +50,20 @@ class AppMgr
55
50
  end
56
51
 
57
52
  def running()
58
- @running.keys
53
+ @app.select {|k,v| v[:running]}.keys
59
54
  end
60
55
 
61
56
  def available()
62
- @available.keys
57
+ @app.select {|k,v| v[:available] == true}.keys
63
58
  end
64
59
 
65
60
  def unload(app_name)
66
- handler_name = @available[app_name].name
67
- @available.delete(app_name)
61
+
62
+ handler_name = @app[app_name][:running].name
63
+
68
64
  if handler_name then
69
65
  Object.send(:remove_const, handler_name)
66
+ @app.delete app_name
70
67
  return "app %s unloaded" % app_name
71
68
  else
72
69
  return "couldn't find app %s" % app_name
@@ -74,10 +71,12 @@ class AppMgr
74
71
  end
75
72
 
76
73
  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(', ')
74
+ app = @app[app_name]
75
+ if app and app[:running] then
76
+ return app[:running].public_methods.map(&:to_s).grep(/call_/).map {|x| x.gsub(/call_/,'').gsub(/_/,'-')}.sort.join(', ')
79
77
  else
80
78
  return "app %s not running" % app_name
81
79
  end
82
80
  end
83
81
  end
82
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: app-mgr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors: []
7
7
 
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-08-02 00:00:00 +01:00
12
+ date: 2010-08-06 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies: []
15
15