collectionadapters 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80a678b0765768108c65062a11887800f8ce44c53b4bfaf3f5b3ba73fb936cf3
|
4
|
+
data.tar.gz: 95ccc58f21132bc6bb24844529be539b0f929d0035c15d42be35679ba7db9bd7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26aa5653ae9e9b288030708a05b7b5ab87598bba0574493b68abb4f599d1ac0a8933ed5f58db55c6760da553cd17a4c00865aa4f9eb5a71c591c7f45cb6089e4
|
7
|
+
data.tar.gz: 8b612237e037d8923be8db0e02c7fb603362e5af113c0e57577092815a080d679f6aeec0635f9e5907fd446ef1406efac17c514d357ce3688cf4b3b52e7bfcda
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module CollectionAdapters
|
2
|
+
class ArraySequel
|
3
|
+
def initialize model:, column:
|
4
|
+
@model = model
|
5
|
+
@col = column.to_sym
|
6
|
+
end
|
7
|
+
|
8
|
+
def << val
|
9
|
+
@model.new.set(@col => val).save
|
10
|
+
rescue Sequel::UniqueConstraintViolation
|
11
|
+
nil
|
12
|
+
end
|
13
|
+
|
14
|
+
def count
|
15
|
+
@model.count
|
16
|
+
end
|
17
|
+
|
18
|
+
def concat other
|
19
|
+
other.each {|v| self << v }
|
20
|
+
end
|
21
|
+
|
22
|
+
def include? key
|
23
|
+
@model[@col => key] != nil
|
24
|
+
end
|
25
|
+
|
26
|
+
def shift
|
27
|
+
@model.db.transaction do
|
28
|
+
if ob = @model.for_update.first
|
29
|
+
v = ob.values[@col]
|
30
|
+
return v if ob.delete
|
31
|
+
raise Sequel::rollback
|
32
|
+
end
|
33
|
+
end
|
34
|
+
nil
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
|
data/lib/collectionadapters.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: collectionadapters
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vidar Hokstad
|
@@ -99,8 +99,8 @@ files:
|
|
99
99
|
- bin/setup
|
100
100
|
- collectionadapters.gemspec
|
101
101
|
- lib/collectionadapters.rb
|
102
|
+
- lib/collectionadapters/array_sequel.rb
|
102
103
|
- lib/collectionadapters/hash_sequel.rb
|
103
|
-
- lib/collectionadapters/hash_sequel.rb~
|
104
104
|
- lib/collectionadapters/version.rb
|
105
105
|
homepage: http://github.com/vidarh/collectionadapters
|
106
106
|
licenses:
|
@@ -1,39 +0,0 @@
|
|
1
|
-
|
2
|
-
module CollectionAdapters
|
3
|
-
# Takes a Sequel model
|
4
|
-
# and provides +#[]+ and +#[]=+
|
5
|
-
# using Sequels API.
|
6
|
-
#
|
7
|
-
# Values are converted silently to String's
|
8
|
-
#
|
9
|
-
# NOTE: You need to require 'sequel'
|
10
|
-
# yourself; this is to allow you to
|
11
|
-
# optionally also use this adapter
|
12
|
-
# with other classes that provide the
|
13
|
-
# same API.
|
14
|
-
#
|
15
|
-
class HashSequel
|
16
|
-
def initialize(model:, keycolumn:, valuecolumn:)
|
17
|
-
@model = model
|
18
|
-
@k = keycolumn.to_sym
|
19
|
-
@v = valuecolumn.to_sym
|
20
|
-
end
|
21
|
-
|
22
|
-
def []= (key, value)
|
23
|
-
key = key.to_s
|
24
|
-
(@model.first(@k => key) || @model.new).set(@k => key, @v => value).save
|
25
|
-
value
|
26
|
-
end
|
27
|
-
|
28
|
-
def [] (key)
|
29
|
-
r = @model[@k => key.to_s]
|
30
|
-
r ? r.values[@v] : nil
|
31
|
-
end
|
32
|
-
|
33
|
-
def delete(key)
|
34
|
-
ob = @model.first(@k => key.to_s)
|
35
|
-
ob.delete
|
36
|
-
ob.values[@v]
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|