Class: AppMgr
- Inherits:
-
Object
- Object
- AppMgr
- Defined in:
- lib/app-mgr.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
Instance Method Summary collapse
- #available ⇒ Object
- #call(app_name) ⇒ Object
- #connect(name) ⇒ Object
- #execute(name, method, params = '') ⇒ Object
-
#initialize(rsf: nil, reg: nil, rsc: nil, debug: true) ⇒ AppMgr
constructor
A new instance of AppMgr.
- #run(name) ⇒ Object
- #running ⇒ Object
- #running?(name) ⇒ Boolean
- #stop(name) ⇒ Object
- #unload(name) ⇒ Object
Constructor Details
#initialize(rsf: nil, reg: nil, rsc: nil, debug: true) ⇒ AppMgr
Returns a new instance of AppMgr.
12 13 14 15 16 17 18 19 20 |
# File 'lib/app-mgr.rb', line 12 def initialize(rsf: nil, reg: nil, rsc: nil, debug: true) @rsf, @reg, @rsc, @debug = rsf, reg, rsc, debug @rscript = RScript.new(type: 'app', debug: debug) @app = {} load_all(rsf) end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
10 11 12 |
# File 'lib/app-mgr.rb', line 10 def app @app end |
Instance Method Details
#available ⇒ Object
22 23 24 |
# File 'lib/app-mgr.rb', line 22 def available() @app.select {|k,v| v[:available] == true}.keys end |
#call(app_name) ⇒ Object
26 27 28 |
# File 'lib/app-mgr.rb', line 26 def call(app_name) @app[app_name.to_sym][:running].call end |
#connect(name) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/app-mgr.rb', line 50 def connect(name) app = @app[name.to_sym] if app and app[:running] then yield(app[:running]) else return "app %s not running" % name end end |
#execute(name, method, params = '') ⇒ Object
30 31 32 |
# File 'lib/app-mgr.rb', line 30 def execute(name, method, params='') @app[name.to_sym][:running].method(method.to_sym).call(params) end |
#run(name) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/app-mgr.rb', line 34 def run(name) app = @app[name.to_sym] class_name = app[:code][/(?<=class )\w+/] app[:running] = eval(class_name + '.new') end |
#running ⇒ Object
42 43 44 |
# File 'lib/app-mgr.rb', line 42 def running() @app.select {|k,v| v[:running]}.keys end |
#running?(name) ⇒ Boolean
46 47 48 |
# File 'lib/app-mgr.rb', line 46 def running?(name) @app[name.to_sym][:running] ? true : false end |
#stop(name) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/app-mgr.rb', line 62 def stop(name) app = @app[name.to_sym] if app.delete(:running) then return "app %s stopped" % name else return "couldn't find app %s" % name end end |
#unload(name) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/app-mgr.rb', line 74 def unload(name) class_name = @app[name.to_sym][:running].class.name if class_name then Object.send(:remove_const, class_name) @app.delete name.to_sym return "app %s unloaded" % name else return "couldn't find app %s" % name end end |