Sha256: f944b13a4ab8d1476972358b2c07f5f941e0470355db8950eedc50c315c3b943

Contents?: true

Size: 717 Bytes

Versions: 1

Compression:

Stored size: 717 Bytes

Contents

module CollectionAdapters
  class ArraySequel
    def initialize model:, column:
      @ds    = model
      @model = model.kind_of?(Sequel::Dataset) ? @ds.model : @ds
      @col   = column.to_sym
    end

    def << val
      @model.new.set(@col => val).save
    rescue Sequel::UniqueConstraintViolation
      nil
    end

    def count
      @model.count
    end

    def concat other
      other.each {|v| self << v }
    end

    def include? key
      @model[@col => key] != nil
    end

    def shift
      @ds.db.transaction do
        if ob = @ds.for_update.first
          v  = ob.values[@col]
          return v if ob.delete
          raise Sequel::rollback
        end
      end
      nil
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
collectionadapters-0.3.0 lib/collectionadapters/array_sequel.rb