Class: AppMainBase

Inherits:
Object
  • Object
show all
Defined in:
lib/template/server_app_base.rb

Direct Known Subclasses

MyApp

Instance Method Summary collapse

Constructor Details

#initializeAppMainBase

Returns a new instance of AppMainBase.



3
4
5
6
7
8
9
# File 'lib/template/server_app_base.rb', line 3

def initialize
  @config = nil
  @aboet = 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
58
59
60
# File 'lib/template/server_app_base.rb', line 43

def add_history(file, history_data, max = 10)
  begin
    buf = File.read "#{$home_dir}history/#{file}"
  rescue
    buf = ""
  end
  data = eval(buf)
  if data == nil
    data = []
  end
  if history_data.to_s != ""
    data.prepend history_data
  end
  data = data.uniq[0..max - 1]
  File.open("#{$home_dir}history/#{file}", "w") do |f|
    f.write JSON.pretty_generate data
  end
end

#app_send(str) ⇒ Object



11
12
13
14
15
# File 'lib/template/server_app_base.rb', line 11

def app_send(str)
  if @ws != nil
    @ws.send(str)
  end
end

#resumeObject



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

#stopObject



29
30
31
32
# File 'lib/template/server_app_base.rb', line 29

def stop()
  @abort = true
  @exec = false
end

#suspendObject



34
35
36
# File 'lib/template/server_app_base.rb', line 34

def suspend()
  @suspend = true
end