Class: ActiveVlc::DSL::Stream

Inherits:
Base
  • Object
show all
Defined in:
lib/activevlc/dsl/stream.rb

Direct Known Subclasses

Duplicate

Instance Method Summary collapse

Methods inherited from Base

#initialize, #param

Constructor Details

This class inherits a constructor from ActiveVlc::DSL::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args, &block) ⇒ Object

FIXME refactor more DRY



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/activevlc/dsl/stream.rb', line 15

def method_missing(sym, *args, &block)
  begin
    klass = ActiveVlc::Stage.const_get sym.to_s.capitalize.to_sym
  rescue
    klass = ActiveVlc::Stage::Base
    args.unshift(sym)
  end

  begin
    dsl_klass = ActiveVlc::DSL.const_get sym.to_s.capitalize.to_sym
  rescue
    dsl_klass = ActiveVlc::DSL::Base
  end

  add_substage(klass, dsl_klass, *args, &block)
end

Instance Method Details

#to(sym_or_hash, &block) ⇒ Object

FIXME This method contains some dirty syntactic sugar as a PoC and need refactor



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/activevlc/dsl/stream.rb', line 33

def to(sym_or_hash, &block)
  if sym_or_hash.is_a?(Hash)
    type, opt = sym_or_hash.first
  else
    type, opt = [sym_or_hash]
  end

  if type == :chain
    to_chain(&block)
  elsif [:file, :standard, :std].include? type
    to_file(opt, &block)
  else
    stage = ActiveVlc::Stage::Base.new(type)
    # Evaluate against the DSL if a block is given
    ActiveVlc::DSL::Base.new(stage).instance_eval(&block) if block_given?
    @context << stage
  end
end

#to_chain(&block) ⇒ Object



52
53
54
55
56
# File 'lib/activevlc/dsl/stream.rb', line 52

def to_chain(&block)
  chain = ActiveVlc::Stage::Chain.new
  ActiveVlc::DSL::Stream.new(chain).instance_eval(&block) if block_given?
  @context << chain
end

#to_file(dst = nil, &block) ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/activevlc/dsl/stream.rb', line 58

def to_file(dst = nil, &block)
  stage = ActiveVlc::Stage::Base.new(:standard)
  stage[:dst] = dst if dst

  # Evaluate against the DSL if a block is given
  ActiveVlc::DSL::Base.new(stage).instance_eval(&block) if block_given?
  @context << stage
end