class ActiveVlc::DSL::Stream

Public Instance Methods

method_missing(sym, *args, &block) click to toggle source

FIXME refactor more DRY

# 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
to(sym_or_hash, &block) click to toggle source

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

# 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) click to toggle source
# 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) click to toggle source
# 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

Protected Instance Methods

add_substage(stage_klass, dsl_klass, *args, &block) click to toggle source
# File lib/activevlc/dsl/stream.rb, line 68
def add_substage(stage_klass, dsl_klass, *args, &block)
  stage = stage_klass.new(*args)
  @context << stage
  dsl = dsl_klass.new(stage)
  dsl.instance_eval &block if block_given?
end