Class: CastCaster::Channel
- Inherits:
-
Object
- Object
- CastCaster::Channel
- Defined in:
- lib/castcaster/channel.rb
Constant Summary collapse
- STATUSES =
%w[stopped live error].freeze
Instance Attribute Summary collapse
-
#engine ⇒ Object
Returns the value of attribute engine.
-
#hls ⇒ Object
Returns the value of attribute hls.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
-
#snapshot ⇒ Object
Returns the value of attribute snapshot.
-
#source ⇒ Object
Returns the value of attribute source.
-
#status ⇒ Object
Returns the value of attribute status.
-
#transcode ⇒ Object
Returns the value of attribute transcode.
Class Method Summary collapse
Instance Method Summary collapse
- #destroy ⇒ Object
-
#initialize(name, attrs = {}) ⇒ Channel
constructor
A new instance of Channel.
- #live? ⇒ Boolean
- #save ⇒ Object
- #to_h ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(name, attrs = {}) ⇒ Channel
Returns a new instance of Channel.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/castcaster/channel.rb', line 8 def initialize(name, attrs = {}) @name = name @engine = attrs['engine'] || 'default' @source = attrs['source'] || {} @hls = attrs['hls'] || { 'fragment' => 6, 'playlist_length' => 60 } @transcode = attrs['transcode'] @snapshot = attrs['snapshot'] @status = attrs['status'] || 'stopped' @path = File.join(self.class.channels_dir, "#{name}.yml") end |
Instance Attribute Details
#engine ⇒ Object
Returns the value of attribute engine.
6 7 8 |
# File 'lib/castcaster/channel.rb', line 6 def engine @engine end |
#hls ⇒ Object
Returns the value of attribute hls.
6 7 8 |
# File 'lib/castcaster/channel.rb', line 6 def hls @hls end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/castcaster/channel.rb', line 5 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
5 6 7 |
# File 'lib/castcaster/channel.rb', line 5 def path @path end |
#snapshot ⇒ Object
Returns the value of attribute snapshot.
6 7 8 |
# File 'lib/castcaster/channel.rb', line 6 def snapshot @snapshot end |
#source ⇒ Object
Returns the value of attribute source.
6 7 8 |
# File 'lib/castcaster/channel.rb', line 6 def source @source end |
#status ⇒ Object
Returns the value of attribute status.
6 7 8 |
# File 'lib/castcaster/channel.rb', line 6 def status @status end |
#transcode ⇒ Object
Returns the value of attribute transcode.
6 7 8 |
# File 'lib/castcaster/channel.rb', line 6 def transcode @transcode end |
Class Method Details
.all ⇒ Object
53 54 55 56 57 |
# File 'lib/castcaster/channel.rb', line 53 def all Dir[File.join(channels_dir, '*.yml')].map do |f| from_file(f) end.compact.sort_by(&:name) end |
.channels_dir ⇒ Object
49 50 51 |
# File 'lib/castcaster/channel.rb', line 49 def channels_dir File.join(Dir.pwd, 'channels') end |
.create(name, attrs = {}) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/castcaster/channel.rb', line 65 def create(name, attrs = {}) ch = new(name, attrs) ch.validate! raise Error, "Channel '#{name}' already exists" if File.exist?(ch.path) ch.save ch end |
.find(name) ⇒ Object
59 60 61 62 63 |
# File 'lib/castcaster/channel.rb', line 59 def find(name) path = File.join(channels_dir, "#{name}.yml") return nil unless File.exist?(path) from_file(path) end |
Instance Method Details
#destroy ⇒ Object
35 36 37 |
# File 'lib/castcaster/channel.rb', line 35 def destroy File.delete(@path) if File.exist?(@path) end |
#live? ⇒ Boolean
39 40 41 |
# File 'lib/castcaster/channel.rb', line 39 def live? @status == 'live' end |
#save ⇒ Object
31 32 33 |
# File 'lib/castcaster/channel.rb', line 31 def save File.write(@path, YAML.dump(to_h)) end |
#to_h ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/castcaster/channel.rb', line 19 def to_h { 'name' => @name, 'engine' => @engine, 'source' => @source, 'hls' => @hls, 'transcode' => @transcode, 'snapshot' => @snapshot, 'status' => @status }.compact end |