Class: CollectionAdapters::ArraySequel
- Inherits:
-
Object
- Object
- CollectionAdapters::ArraySequel
- Defined in:
- lib/collectionadapters/array_sequel.rb
Instance Method Summary collapse
- #<<(val) ⇒ Object
- #concat(other) ⇒ Object
- #count ⇒ Object
- #include?(key) ⇒ Boolean
-
#initialize(model:, column:) ⇒ ArraySequel
constructor
A new instance of ArraySequel.
- #shift ⇒ Object
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 |
#count ⇒ Object
14 15 16 |
# File 'lib/collectionadapters/array_sequel.rb', line 14 def count @model.count end |
#include?(key) ⇒ Boolean
22 23 24 |
# File 'lib/collectionadapters/array_sequel.rb', line 22 def include? key @model[@col => key] != nil end |
#shift ⇒ Object
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 |