Class: AppMgr

Inherits:
Object
  • Object
show all
Defined in:
lib/app-mgr.rb

Instance Method Summary collapse

Constructor Details

#initialize(rsf: nil, type: 'app', debug: false) ⇒ AppMgr

Returns a new instance of AppMgr.



16
17
18
19
20
21
22
23
24
# File 'lib/app-mgr.rb', line 16

def initialize(rsf: nil, type: 'app', debug: false)

  @rsf, @type, @debug = rsf, type, debug
  @rscript = RScript.new(type: type, cache: nil, debug: debug)
  @app = {}

  load_all(rsf)

end

Instance Method Details

#[](name) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/app-mgr.rb', line 26

def [](name)

  app = @app[name.to_sym]

  return app[:running] if app and app[:running]

end

#availableObject



34
35
36
# File 'lib/app-mgr.rb', line 34

def available()
  @app.keys
end

#load_app(name) ⇒ Object



113
114
115
116
117
118
119
120
121
122
# File 'lib/app-mgr.rb', line 113

def load_app(name)

  codeblock, _, attr = @rscript.read(["//#{@type}:" + name.to_s, @rsf])

  return if attr[:disabled] == 'true'

  puts 'codeblock: ' + codeblock.inspect if @debug
  @app[name][:code] = codeblock
  return @app[name]
end

#restart(name) ⇒ Object



38
39
40
41
42
# File 'lib/app-mgr.rb', line 38

def restart(name)
  load_app(name)
  run(name)
  name.to_s + ' restarted'
end

#run(name) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/app-mgr.rb', line 44

def run(name)

  app = @app[name.to_sym]

  #app[:running] = eval(app[:code])
  app[:running] = Runner.new.run(app[:code])

end

#runningObject



53
54
55
# File 'lib/app-mgr.rb', line 53

def running()
  @app.select {|k,v| v[:running]}.keys
end

#running?(name) ⇒ Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/app-mgr.rb', line 57

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
87
# File 'lib/app-mgr.rb', line 74

def unload(name)

  app = @app[name.to_sym]

  if class_name then

    @app.delete name.to_sym
    return "app %s unloaded" % name

  else
    return "couldn't find app %s" % name
  end

end