Module: Shelr
- Defined in:
- lib/shelr.rb,
lib/shelr/player.rb,
lib/shelr/ttyrec.rb,
lib/shelr/version.rb,
lib/shelr/recorder.rb,
lib/shelr/terminal.rb,
lib/shelr/publisher.rb
Defined Under Namespace
Classes: Player, Publisher, Recorder, TTYRec, Terminal
Constant Summary
collapse
- APP_NAME =
'shelr'
- API_URL =
ENV['SHELR_LOCAL'] ? 'http://localhost:3000' : 'http://shelr.tv'
- XDG_DATA_DIR =
ENV['XDG_DATA_HOME'] || File.join(ENV['HOME'], '.local', 'share')
- XDG_CONFIG_DIR =
ENV['XDG_CONFIG_HOME'] || File.join(ENV['HOME'], '.config')
- DATA_DIR =
File.join(XDG_DATA_DIR, APP_NAME)
- CONFIG_DIR =
File.join(XDG_CONFIG_DIR, APP_NAME)
- API_KEY_CFG =
File.join(CONFIG_DIR, 'api_key')
- BACKEND_CFG =
File.join(CONFIG_DIR, 'backend')
- VERSION =
'0.12.9'
Class Method Summary
collapse
Class Method Details
.api_key ⇒ Object
23
24
25
26
|
# File 'lib/shelr.rb', line 23
def api_key
return false unless File.exist?(API_KEY_CFG)
@api_key ||= File.read(API_KEY_CFG).strip
end
|
.api_key=(key) ⇒ Object
28
29
30
31
|
# File 'lib/shelr.rb', line 28
def api_key=(key)
ensure_config_dir_exist
File.open(API_KEY_CFG, 'w+') { |f| f.puts(key.strip) }
end
|
.backend ⇒ Object
33
34
35
|
# File 'lib/shelr.rb', line 33
def backend
@backend ||= File.exist?(BACKEND_CFG) ? File.read(BACKEND_CFG).strip : 'script'
end
|
.backend=(bin) ⇒ Object
37
38
39
40
41
42
43
44
|
# File 'lib/shelr.rb', line 37
def backend=(bin)
unless ['script', 'ttyrec'].include?(bin)
puts "Backend should be either `script` or `ttyrec`"
exit 1
end
ensure_config_dir_exist
File.open(BACKEND_CFG, 'w+') { |f| f.puts(bin.strip) }
end
|
.data_dir(record_id) ⇒ Object
46
47
48
49
|
# File 'lib/shelr.rb', line 46
def data_dir(record_id)
id = record_id.strip == 'last' ? last_id : record_id.to_s
File.join(DATA_DIR, id)
end
|
.last_id ⇒ Object
51
52
53
|
# File 'lib/shelr.rb', line 51
def last_id
File.basename(Dir[File.join(DATA_DIR, '*')].sort.last)
end
|
.terminal ⇒ Object
55
56
57
|
# File 'lib/shelr.rb', line 55
def terminal
@terminal ||= Shelr::Terminal.new
end
|