Sha256: 5773028e267f38073099017b530820fba19e7b32b92b04dffc7c9d125bb4b736

Contents?: true

Size: 1.01 KB

Versions: 4

Compression:

Stored size: 1.01 KB

Contents

require 'zygote/memory'

module Zygote
  # An entry into the queue
  class CellQueueEntry < SuperModel::Base
    include SuperModel::Marshal::Model
  end

  # A means of storing Cell queue data for a given sku
  module CellQueue
    extend self
    COLLECTION = :assets
    ARRAY_KEY = :cell_queue
    Memory.load

    def push(key, data)
      entry = CellQueueEntry.find_by_name(key)
      unless entry
        entry = CellQueueEntry.new(name: key, data: [])
        entry.save
      end
      entry.data << data
      entry.save
      Memory.save
    end

    def shift(key)
      entry = CellQueueEntry.find_by_name(key)
      return nil unless entry
      first = entry.data.shift
      entry.save
      Memory.save
      first
    end

    def show(key)
      entry = CellQueueEntry.find_by_name(key)
      entry ? entry.data : []
    end

    def purge(key)
      entry = CellQueueEntry.find_by_name(key)
      entry.data = [] if entry
      entry.save if entry
    end

    def all
      CellQueueEntry.all
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
zygote-0.2.15 lib/zygote/cell_queue.rb
zygote-0.2.14 lib/zygote/cell_queue.rb
zygote-0.2.13 lib/zygote/cell_queue.rb
zygote-0.2.12 lib/zygote/cell_queue.rb