Class: CollectionAdapters::ArraySequel

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

Instance Method Summary collapse

Constructor Details

#initialize(model:, column:) ⇒ ArraySequel

Returns a new instance of ArraySequel.



3
4
5
6
# File 'lib/collectionadapters/array_sequel.rb', line 3

def initialize model:, column:
  @model = model
  @col   = column.to_sym
end

Instance Method Details

#<<(val) ⇒ Object



8
9
10
11
12
# File 'lib/collectionadapters/array_sequel.rb', line 8

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

#concat(other) ⇒ Object



18
19
20
# File 'lib/collectionadapters/array_sequel.rb', line 18

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

#countObject



14
15
16
# File 'lib/collectionadapters/array_sequel.rb', line 14

def count
  @model.count
end

#include?(key) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/collectionadapters/array_sequel.rb', line 22

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

#shiftObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/collectionadapters/array_sequel.rb', line 26

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