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'
- 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')
- API_URL_CFG =
File.join(CONFIG_DIR, 'api_url')
- BACKEND_CFG =
File.join(CONFIG_DIR, 'backend')
- VERSION =
'0.16.3'
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
|
.api_url ⇒ Object
33
34
35
36
|
# File 'lib/shelr.rb', line 33
def api_url
return ENV['SHELR_LOCAL'] ? 'http://localhost:3000' : 'http://shelr.tv' unless File.exist?(API_URL_CFG)
@api_url ||= File.read(API_URL_CFG).strip
end
|
.api_url=(url) ⇒ Object
38
39
40
41
|
# File 'lib/shelr.rb', line 38
def api_url=(url)
ensure_config_dir_exist
File.open(API_URL_CFG, 'w+') { |f| f.puts(url.strip) }
end
|
.backend ⇒ Object
43
44
45
|
# File 'lib/shelr.rb', line 43
def backend
@backend ||= File.exist?(BACKEND_CFG) ? File.read(BACKEND_CFG).strip : 'script'
end
|
.backend=(bin) ⇒ Object
47
48
49
50
51
52
53
54
|
# File 'lib/shelr.rb', line 47
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
56
57
58
59
|
# File 'lib/shelr.rb', line 56
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
61
62
63
|
# File 'lib/shelr.rb', line 61
def last_id
File.basename(Dir[File.join(DATA_DIR, '*')].sort.last)
end
|
.terminal ⇒ Object
65
66
67
|
# File 'lib/shelr.rb', line 65
def terminal
@terminal ||= Shelr::Terminal.new
end
|