Class: Musa::Series::Constructors::QueueSerie

Inherits:
Object
  • Object
show all
Defined in:
lib/musa-dsl/series/queue-serie.rb

Instance Method Summary collapse

Constructor Details

#initialize(series) ⇒ QueueSerie

Returns a new instance of QueueSerie.



12
13
14
15
# File 'lib/musa-dsl/series/queue-serie.rb', line 12

def initialize(series)
  self.sources = series
  init
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, **key_args, &block) ⇒ Object (private)



71
72
73
74
75
76
77
# File 'lib/musa-dsl/series/queue-serie.rb', line 71

private def method_missing(method_name, *args, **key_args, &block)
  if @current&.respond_to?(method_name)
    @current.send method_name, *args, **key_args, &block
  else
    super
  end
end

Instance Method Details

#<<(serie) ⇒ Object

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
24
25
26
27
# File 'lib/musa-dsl/series/queue-serie.rb', line 17

def <<(serie)
  # when queue is a prototype it is also frozen so no serie can be added (it would raise an Exception if tried).
  # when queue is an instance the added serie should also be an instance (raise an Exception otherwise)
  #
  raise ArgumentError, "Only an instance serie can be queued" unless serie.instance?

  @sources << serie
  @current ||= @sources[@index]

  self
end

#clearObject



29
30
31
32
33
# File 'lib/musa-dsl/series/queue-serie.rb', line 29

def clear
  @sources.clear
  init
  self
end

#infinite?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/musa-dsl/series/queue-serie.rb', line 61

def infinite?
  !!@sources.find(&:infinite?)
end