Sha256: 98fabf111089f47054c1d6e0a5f60a4d3960d5538883751dcc9c3428d77da4c1

Contents?: true

Size: 774 Bytes

Versions: 1

Compression:

Stored size: 774 Bytes

Contents

class ListStateNotifier
  attr_reader :items

  def initialize
    @items = []
    @listeners = []
  end

  def set_all(objects)
    @items = objects
    notify_listeners
  end

  def add(object)
    @items << object
    notify_listeners
  end

  def get(number)
    @items[number]
  end

  def delete(object)
    @items.delete(object)
    notify_listeners
  end

  def replace(object, new_object)
    index = @items.index(object)
    @items[index] = new_object
    notify_listeners
  end

  def add_listener(listener)
    @listeners << listener
  end

  def delete_listener(listener)
    @listeners.delete(listener)
  end

  def notify_listeners
    @listeners.each do |listener|
      listener.update(@items)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jewerly_system-1.0.0 lib/source/state_holders/list_state_notifier.rb