Class: AppMainBase
- Inherits:
-
Object
- Object
- AppMainBase
- Defined in:
- lib/template/server_app_base.rb
Direct Known Subclasses
Instance Method Summary collapse
-
#add_history(file, history_data, max = 10) ⇒ Object
履歴の保存.
- #app_send(str) ⇒ Object
-
#initialize ⇒ AppMainBase
constructor
A new instance of AppMainBase.
- #resume ⇒ Object
- #set_config(config) ⇒ Object
- #set_ws(ws) ⇒ Object
- #start(argv) ⇒ Object
- #stop ⇒ Object
- #suspend ⇒ Object
Constructor Details
#initialize ⇒ AppMainBase
Returns a new instance of AppMainBase.
5 6 7 8 9 10 11 |
# File 'lib/template/server_app_base.rb', line 5 def initialize @config = nil @abort = false @exec = false @suspend = false @ws = nil end |
Instance Method Details
#add_history(file, history_data, max = 10) ⇒ Object
履歴の保存
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/template/server_app_base.rb', line 43 def add_history(file, history_data, max = 10) history_dir = @config&.fetch(:home_dir, "./") + "history/" path = File.join(history_dir, file) begin buf = File.read(path) data = JSON.parse(buf) rescue data = [] end if history_data.to_s != "" data.unshift(history_data) end data = data.uniq[0, max] File.write(path, JSON.pretty_generate(data)) end |
#app_send(str) ⇒ Object
13 14 15 |
# File 'lib/template/server_app_base.rb', line 13 def app_send(str) @ws&.send(str) end |
#resume ⇒ Object
38 39 40 |
# File 'lib/template/server_app_base.rb', line 38 def resume @suspend = false end |
#set_config(config) ⇒ Object
21 22 23 |
# File 'lib/template/server_app_base.rb', line 21 def set_config(config) @config = config end |
#set_ws(ws) ⇒ Object
17 18 19 |
# File 'lib/template/server_app_base.rb', line 17 def set_ws(ws) @ws = ws end |
#start(argv) ⇒ Object
25 26 27 |
# File 'lib/template/server_app_base.rb', line 25 def start(argv) @exec = true end |
#stop ⇒ Object
29 30 31 32 |
# File 'lib/template/server_app_base.rb', line 29 def stop @abort = true @exec = false end |
#suspend ⇒ Object
34 35 36 |
# File 'lib/template/server_app_base.rb', line 34 def suspend @suspend = true end |