Class: BoPeep::Playlist

Inherits:
Object
  • Object
show all
Defined in:
lib/bopeep.rb

Defined Under Namespace

Classes: Start

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context) ⇒ Playlist

Returns a new instance of Playlist.



1592
1593
1594
1595
# File 'lib/bopeep.rb', line 1592

def initialize(context)
  @context = context
  @start = @insert_at = Start.new
end

Instance Attribute Details

#insert_atObject (readonly)

Returns the value of attribute insert_at.



1590
1591
1592
# File 'lib/bopeep.rb', line 1590

def insert_at
  @insert_at
end

Instance Method Details

#playObject



1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
# File 'lib/bopeep.rb', line 1597

def play
  playing = @insert_at = @start
  command = nil
  on_failure_command_used = false

  while playing.next
    playing = @insert_at = playing.next

    if command != playing.command
      command = playing.command

      playing.log_command
    end

    playing.log_step

    result = playing.run

    if result.failed?
      if @context.on_failure_command && on_failure_command_used == false
        playing.next = nil
        @context.on_failure_command.(@context)
        # Prevents infinite loops if `on_failure_command` fails
        on_failure_command_used = true
      else
        # This is redefined in `test/test_helper.rb` to avoid exiting the test process
        exit 1
      end
    end
  end
end

#queue(command_step) ⇒ Object



1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
# File 'lib/bopeep.rb', line 1629

def queue(command_step)
  if @insert_at.next
    command_step.next = @insert_at.next
  end

  command_step.previous = @insert_at
  @insert_at.next = command_step

  @insert_at = command_step
end