Class: CastCaster::Config
- Inherits:
-
Object
- Object
- CastCaster::Config
- Defined in:
- lib/castcaster/config.rb
Constant Summary collapse
- DEFAULTS =
{ 'engine' => 'nginx-rtmp', 'hls_fragment' => 6, 'hls_window' => 60, 'domain' => '', 'acme_email' => 'admin@example.com', 'enable_traefik' => false }.freeze
Instance Method Summary collapse
- #ensure_project_dirs ⇒ Object
- #ensure_token ⇒ Object
-
#initialize(path = nil) ⇒ Config
constructor
A new instance of Config.
- #load ⇒ Object
- #load_token ⇒ Object
- #save(data) ⇒ Object
Constructor Details
#initialize(path = nil) ⇒ Config
Returns a new instance of Config.
12 13 14 |
# File 'lib/castcaster/config.rb', line 12 def initialize(path = nil) @path = path || default_config_path end |
Instance Method Details
#ensure_project_dirs ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/castcaster/config.rb', line 29 def ensure_project_dirs project_dir = Dir.pwd FileUtils.mkdir_p(File.join(project_dir, 'channels')) FileUtils.mkdir_p(File.join(project_dir, 'hls')) FileUtils.mkdir_p(File.join(project_dir, 'nginx')) FileUtils.mkdir_p(File.join(project_dir, 'logs')) FileUtils.mkdir_p(File.join(project_dir, 'data')) project_dir end |
#ensure_token ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/castcaster/config.rb', line 39 def ensure_token path = File.join(Dir.pwd, 'castcaster.token') return File.read(path).strip if File.exist?(path) token = SecureRandom.hex(32) File.open(path, 'w', 0600) { |f| f.write(token) } token end |
#load ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/castcaster/config.rb', line 16 def load return DEFAULTS.dup unless File.exist?(@path) cfg = YAML.safe_load(File.read(@path)) || {} DEFAULTS.merge(cfg) rescue => e raise Error, "Config corrupted: #{e.}" end |
#load_token ⇒ Object
47 48 49 50 51 |
# File 'lib/castcaster/config.rb', line 47 def load_token path = File.join(Dir.pwd, 'castcaster.token') return nil unless File.exist?(path) File.read(path).strip end |
#save(data) ⇒ Object
24 25 26 27 |
# File 'lib/castcaster/config.rb', line 24 def save(data) FileUtils.mkdir_p(File.dirname(@path)) File.write(@path, YAML.dump(data)) end |