active_orm 4.0.3 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,27 +1,31 @@
1
- class ActiveOrm::Redis::Geo < ActiveOrm::Redis
1
+ # frozen_string_literal: true
2
2
 
3
- def self.create
4
- # TODO
5
- end
3
+ class ActiveOrm::Redis::Geo < ActiveOrm::Redis::Base
4
+ class << self
6
5
 
7
- def self.hash
8
- # TODO
9
- end
6
+ def create
7
+ # TODO
8
+ end
10
9
 
11
- def self.position
12
- # TODO
13
- end
10
+ def hash
11
+ # TODO
12
+ end
14
13
 
15
- def self.distance
16
- # TODO
17
- end
14
+ def position
15
+ # TODO
16
+ end
18
17
 
19
- def self.radius
20
- # TODO
21
- end
18
+ def distance
19
+ # TODO
20
+ end
22
21
 
23
- def self.radius_member
24
- # TODO
25
- end
22
+ def radius
23
+ # TODO
24
+ end
26
25
 
26
+ def radius_member
27
+ # TODO
28
+ end
29
+
30
+ end
27
31
  end
@@ -1,75 +1,79 @@
1
- class ActiveOrm::Redis::Hash < ActiveOrm::Redis
1
+ # frozen_string_literal: true
2
2
 
3
- def self.find(key, field)
4
- value = client.hget(normalize_key(key), field)
5
- value = metamorph(value) if evaluate?
6
- value
7
- end
3
+ class ActiveOrm::Redis::Hash < ActiveOrm::Redis::Base
4
+ class << self
8
5
 
9
- def self.find_each(key, *args)
10
- value = client.hmget(normalize_key(key), args)
11
- value = metamorph(value) if evaluate?
12
- value
13
- end
6
+ def find(key, field)
7
+ value = client.hget(normalize_key(key), field)
8
+ value = metamorph(value) if evaluate?
9
+ value
10
+ end
14
11
 
15
- def self.all(key)
16
- value = client.hgetall(normalize_key(key))
17
- value = metamorph(value) if evaluate?
18
- value
19
- end
12
+ def find_each(key, *args)
13
+ value = client.hmget(normalize_key(key), args)
14
+ value = metamorph(value) if evaluate?
15
+ value
16
+ end
20
17
 
21
- def self.keys(key)
22
- value = client.hkeys(normalize_key(key))
23
- value = metamorph(value) if evaluate?
24
- value
25
- end
18
+ def all(key)
19
+ value = client.hgetall(normalize_key(key))
20
+ value = metamorph(value) if evaluate?
21
+ value
22
+ end
26
23
 
27
- def self.values(key)
28
- value = client.hvals(normalize_key(key))
29
- value = metamorph(value) if evaluate?
30
- value
31
- end
24
+ def keys(key)
25
+ value = client.hkeys(normalize_key(key))
26
+ value = metamorph(value) if evaluate?
27
+ value
28
+ end
32
29
 
33
- def self.value_length(key, field)
34
- client.hstrlen(normalize_key(key), field)
35
- end
30
+ def values(key)
31
+ value = client.hvals(normalize_key(key))
32
+ value = metamorph(value) if evaluate?
33
+ value
34
+ end
36
35
 
37
- def self.count(key)
38
- client.hlen(normalize_key(key))
39
- end
36
+ def value_length(key, field)
37
+ client.hstrlen(normalize_key(key), field)
38
+ end
40
39
 
41
- def self.exists?(key, field)
42
- client.hexists(normalize_key(key), field)
43
- end
40
+ def count(key)
41
+ client.hlen(normalize_key(key))
42
+ end
44
43
 
45
- def self.create(key, field, value)
46
- client.hset(normalize_key(key), field, value)
47
- end
44
+ def exists?(key, field)
45
+ client.hexists(normalize_key(key), field)
46
+ end
48
47
 
49
- def self.create!(key, field, value)
50
- client.hsetnx(normalize_key(key), field, value)
51
- end
48
+ def create(key, field, value)
49
+ client.hset(normalize_key(key), field, value)
50
+ end
52
51
 
53
- def self.create_each(key, *args)
54
- client.hmset(normalize_key(key), args)
55
- end
52
+ def create!(key, field, value)
53
+ client.hsetnx(normalize_key(key), field, value)
54
+ end
55
+
56
+ def create_each(key, *args)
57
+ client.hmset(normalize_key(key), args)
58
+ end
56
59
 
57
- def self.increment(key, field, value)
58
- normalized_key = normalize_key(key)
60
+ def increment(key, field, value)
61
+ normalized_key = normalize_key(key)
59
62
 
60
- if value.is_a?(Float)
61
- client.hincrbyfloat(normalized_key, field, value)
62
- else
63
- client.hincrby(normalized_key, field, value)
63
+ if value.is_a?(Float)
64
+ client.hincrbyfloat(normalized_key, field, value)
65
+ else
66
+ client.hincrby(normalized_key, field, value)
67
+ end
64
68
  end
65
- end
66
69
 
67
- def self.destroy(key, *args)
68
- client.hdel(normalize_key(key), args)
69
- end
70
+ def destroy(key, *args)
71
+ client.hdel(normalize_key(key), args)
72
+ end
70
73
 
71
- def self.scan(key, cursor, opts = {})
72
- client.hdel(normalize_key(key), cursor, opts)
73
- end
74
+ def scan(key, cursor, opts = {})
75
+ client.hdel(normalize_key(key), cursor, opts)
76
+ end
74
77
 
78
+ end
75
79
  end
@@ -1,15 +1,19 @@
1
- class ActiveOrm::Redis::HyperLogLog < ActiveOrm::Redis
1
+ # frozen_string_literal: true
2
2
 
3
- def self.create(key, member)
4
- client.pfadd(normalize_key(key), member)
5
- end
3
+ class ActiveOrm::Redis::HyperLogLog < ActiveOrm::Redis::Base
4
+ class << self
6
5
 
7
- def self.count(*args)
8
- client.pfcount(args)
9
- end
6
+ def create(key, member)
7
+ client.pfadd(normalize_key(key), member)
8
+ end
10
9
 
11
- def self.merge(key, *keys)
12
- client.pfmerge(normalize_key(key), keys)
13
- end
10
+ def count(*args)
11
+ client.pfcount(args)
12
+ end
14
13
 
14
+ def merge(key, *keys)
15
+ client.pfmerge(normalize_key(key), keys)
16
+ end
17
+
18
+ end
15
19
  end
@@ -1,91 +1,95 @@
1
- class ActiveOrm::Redis::Key < ActiveOrm::Redis
1
+ # frozen_string_literal: true
2
2
 
3
- def self.exists?(key)
4
- client.exists(normalize_key(key))
5
- end
3
+ class ActiveOrm::Redis::Key < ActiveOrm::Redis::Base
4
+ class << self
6
5
 
7
- def self.type?(key)
8
- client.type(normalize_key(key))
9
- end
6
+ def exists?(key)
7
+ client.exists(normalize_key(key))
8
+ end
10
9
 
11
- def self.ttl?(key, format = :seconds)
12
- normalized_key = normalize_key(key)
10
+ def type?(key)
11
+ client.type(normalize_key(key))
12
+ end
13
13
 
14
- seconds?(format) ? client.ttl(normalized_key) : client.pttl(normalized_key)
15
- end
14
+ def ttl?(key, format = :seconds)
15
+ normalized_key = normalize_key(key)
16
16
 
17
- def self.sort(key, opts = {})
18
- client.sort(normalize_key(key), opts)
19
- end
17
+ seconds?(format) ? client.ttl(normalized_key) : client.pttl(normalized_key)
18
+ end
20
19
 
21
- def self.sample
22
- client.randomkey
23
- end
20
+ def sort(key, opts = {})
21
+ client.sort(normalize_key(key), opts)
22
+ end
24
23
 
25
- def self.rename(key, value)
26
- client.rename(normalize_key(key), value.to_s)
27
- end
24
+ def sample
25
+ client.randomkey
26
+ end
28
27
 
29
- def self.rename!(key, value)
30
- client.renamenx(normalize_key(key), value.to_s)
31
- end
28
+ def rename(key, value)
29
+ client.rename(normalize_key(key), value.to_s)
30
+ end
32
31
 
33
- def self.destroy(key)
34
- client.del(normalize_key(key))
35
- end
32
+ def rename!(key, value)
33
+ client.renamenx(normalize_key(key), value.to_s)
34
+ end
36
35
 
37
- def self.persist(key)
38
- client.persist(normalize_key(key))
39
- end
36
+ def destroy(key)
37
+ client.del(normalize_key(key))
38
+ end
39
+
40
+ def persist(key)
41
+ client.persist(normalize_key(key))
42
+ end
40
43
 
41
- def self.expire(key, seconds, format = :seconds)
42
- normalized_key = normalize_key(key)
44
+ def expire(key, seconds, format = :seconds)
45
+ normalized_key = normalize_key(key)
43
46
 
44
- if seconds?(format)
45
- client.expire(normalized_key, seconds)
46
- else
47
- client.pexpire(normalized_key, seconds)
47
+ if seconds?(format)
48
+ client.expire(normalized_key, seconds)
49
+ else
50
+ client.pexpire(normalized_key, seconds)
51
+ end
48
52
  end
49
- end
50
53
 
51
- def self.expire_at(key, seconds, format = :seconds)
52
- normalized_key = normalize_key(key)
54
+ def expire_at(key, seconds, format = :seconds)
55
+ normalized_key = normalize_key(key)
53
56
 
54
- if seconds?(format)
55
- client.expireat(normalized_key, seconds)
56
- else
57
- client.pexpireat(normalized_key, seconds)
57
+ if seconds?(format)
58
+ client.expireat(normalized_key, seconds)
59
+ else
60
+ client.pexpireat(normalized_key, seconds)
61
+ end
58
62
  end
59
- end
60
63
 
61
- def self.dump(key)
62
- client.dump(normalize_key(key))
63
- end
64
+ def dump(key)
65
+ client.dump(normalize_key(key))
66
+ end
64
67
 
65
- def self.match(pattern = '*')
66
- value = client.keys(normalize_key(pattern))
67
- value = nil if value.empty?
68
- value
69
- end
68
+ def match(pattern = '*')
69
+ value = client.keys(normalize_key(pattern))
70
+ value = nil if value.empty?
71
+ value
72
+ end
70
73
 
71
- def self.migrate(key, options)
72
- client.migrate(normalize_key(key), options)
73
- end
74
+ def migrate(key, options)
75
+ client.migrate(normalize_key(key), options)
76
+ end
74
77
 
75
- def self.move(key, destination)
76
- client.move(normalize_key(key), destination)
77
- end
78
+ def move(key, destination)
79
+ client.move(normalize_key(key), destination)
80
+ end
78
81
 
79
- def self.object(*args)
80
- client.object(args)
81
- end
82
+ def object(*args)
83
+ client.object(args)
84
+ end
82
85
 
83
- def self.restore(key, milliseconds, value)
84
- client.restore(normalize_key(key), milliseconds, value)
85
- end
86
+ def restore(key, milliseconds, value)
87
+ client.restore(normalize_key(key), milliseconds, value)
88
+ end
86
89
 
87
- def self.scan(cursor, opts = {})
88
- client.scan(cursor, opts)
89
- end
90
+ def scan(cursor, opts = {})
91
+ client.scan(cursor, opts)
92
+ end
90
93
 
94
+ end
91
95
  end
@@ -1,125 +1,129 @@
1
- class ActiveOrm::Redis::List < ActiveOrm::Redis
1
+ # frozen_string_literal: true
2
+
3
+ class ActiveOrm::Redis::List < ActiveOrm::Redis::Base
4
+ class << self
5
+
6
+ def find(key, position = 1)
7
+ value = client.lindex(normalize_key(key), (position - 1))
8
+ value = metamorph(value) if evaluate?
9
+ value
10
+ end
11
+
12
+ def first(key, limit = 1)
13
+ value = client.lrange(normalize_key(key), 0, -1)
14
+ value = (limit == 1 ? value.first : value.first(limit))
15
+ value = metamorph(value) if evaluate?
16
+ value
17
+ end
18
+
19
+ def last(key, limit = 1)
20
+ value = client.lrange(normalize_key(key), 0, -1)
21
+ value = (limit == 1 ? value.last : value.last(limit))
22
+ value = metamorph(value) if evaluate?
23
+ value
24
+ end
25
+
26
+ def between(key, start = 1, finish = 0)
27
+ value = client.lrange(normalize_key(key), (start - 1), (finish - 1))
28
+ metatransform(value)
29
+ end
30
+
31
+ def all(key)
32
+ value = client.lrange(normalize_key(key), 0, -1)
33
+ metatransform(value)
34
+ end
35
+
36
+ def count(key)
37
+ client.llen(normalize_key(key))
38
+ end
39
+
40
+ def create(key, value, order = :prepend)
41
+ normalized_key = normalize_key(key)
42
+
43
+ append?(order) ? client.rpush(normalized_key, value) : client.lpush(normalized_key, value)
44
+ end
45
+
46
+ def create!(key, value, order = :prepend)
47
+ normalized_key = normalize_key(key)
48
+
49
+ append?(order) ? client.rpushx(normalized_key, value) : client.lpushx(normalized_key, value)
50
+ end
51
+
52
+ def create_limit(key, value, limit, order = :prepend)
53
+ normalized_key = normalize_key(key)
54
+
55
+ append?(order) ? client.rpush(normalized_key, value) : client.lpush(normalized_key, value)
56
+ client.ltrim(normalized_key, 0, (limit - 1))
57
+ end
58
+
59
+ def create_limit!(key, value, limit, order = :prepend)
60
+ normalized_key = normalize_key(key)
61
+
62
+ append?(order) ? client.rpushx(normalized_key, value) : client.lpushx(normalized_key, value)
63
+ client.ltrim(normalized_key, 0, (limit - 1))
64
+ end
65
+
66
+ def create_before(key, pivot, value)
67
+ client.linsert(normalize_key(key), :before, pivot, value)
68
+ end
69
+
70
+ def create_after(key, pivot, value)
71
+ client.linsert(normalize_key(key), :after, pivot, value)
72
+ end
73
+
74
+ def update(key, index, value)
75
+ client.lset(normalize_key(key), index, value)
76
+ end
77
+
78
+ def move(key, desination)
79
+ value = client.rpoplpush(normalize_key(key), normalize_key(desination))
80
+ value = metamorph(value) if evaluate?
81
+ value
82
+ end
83
+
84
+ def move_blocking(key, desination)
85
+ value = brpoplpush(normalize_key(key), normalize_key(desination))
86
+ value = metamorph(value) if evaluate?
87
+ value
88
+ end
89
+
90
+ def destroy(key, count, value)
91
+ client.lrem(normalize_key(key), count, value)
92
+ end
93
+
94
+ def destroy_first(key, limit = 1)
95
+ client.ltrim(normalize_key(key), limit, -1)
96
+ end
97
+
98
+ def destroy_last(key, limit = 1)
99
+ client.ltrim(normalize_key(key), 0, -(limit + 1))
100
+ end
101
+
102
+ def destroy_except(key, start, finish)
103
+ client.ltrim(normalize_key(key), (start - 1), (finish - 1))
104
+ end
105
+
106
+ def destroy_all(key)
107
+ client.ltrim(normalize_key(key), -1, 0)
108
+ end
109
+
110
+ def pop(key, order = :prepend)
111
+ value = append?(order) ? client.rpop(key) : client.lpop(key)
112
+ value = metamorph(value) if evaluate?
113
+ value
114
+ end
115
+
116
+ def pop_blocking(keys, opts = {})
117
+ timeout = opts[:timeout] || 0
118
+ value = if append?(opts[:order] || :prepend)
119
+ client.brpop(keys, timeout)
120
+ else
121
+ client.blpop(keys, timeout)
122
+ end
2
123
 
3
- def self.find(key, position = 1)
4
- value = client.lindex(normalize_key(key), (position - 1))
5
- value = metamorph(value) if evaluate?
6
- value
7
- end
8
-
9
- def self.first(key, limit = 1)
10
- value = client.lrange(normalize_key(key), 0, -1)
11
- value = (limit == 1 ? value.first : value.first(limit))
12
- value = metamorph(value) if evaluate?
13
- value
14
- end
15
-
16
- def self.last(key, limit = 1)
17
- value = client.lrange(normalize_key(key), 0, -1)
18
- value = (limit == 1 ? value.last : value.last(limit))
19
- value = metamorph(value) if evaluate?
20
- value
21
- end
22
-
23
- def self.between(key, start = 1, finish = 0)
24
- value = client.lrange(normalize_key(key), (start - 1), (finish - 1))
25
- metatransform(value)
26
- end
27
-
28
- def self.all(key)
29
- value = client.lrange(normalize_key(key), 0, -1)
30
- metatransform(value)
31
- end
32
-
33
- def self.count(key)
34
- client.llen(normalize_key(key))
35
- end
36
-
37
- def self.create(key, value, order = :prepend)
38
- normalized_key = normalize_key(key)
124
+ value = metamorph(value) if evaluate?
125
+ value
126
+ end
39
127
 
40
- append?(order) ? client.rpush(normalized_key, value) : client.lpush(normalized_key, value)
41
128
  end
42
-
43
- def self.create!(key, value, order = :prepend)
44
- normalized_key = normalize_key(key)
45
-
46
- append?(order) ? client.rpushx(normalized_key, value) : client.lpushx(normalized_key, value)
47
- end
48
-
49
- def self.create_limit(key, value, limit, order = :prepend)
50
- normalized_key = normalize_key(key)
51
-
52
- append?(order) ? client.rpush(normalized_key, value) : client.lpush(normalized_key, value)
53
- client.ltrim(normalized_key, 0, (limit - 1))
54
- end
55
-
56
- def self.create_limit!(key, value, limit, order = :prepend)
57
- normalized_key = normalize_key(key)
58
-
59
- append?(order) ? client.rpushx(normalized_key, value) : client.lpushx(normalized_key, value)
60
- client.ltrim(normalized_key, 0, (limit - 1))
61
- end
62
-
63
- def self.create_before(key, pivot, value)
64
- client.linsert(normalize_key(key), :before, pivot, value)
65
- end
66
-
67
- def self.create_after(key, pivot, value)
68
- client.linsert(normalize_key(key), :after, pivot, value)
69
- end
70
-
71
- def self.update(key, index, value)
72
- client.lset(normalize_key(key), index, value)
73
- end
74
-
75
- def self.move(key, desination)
76
- value = client.rpoplpush(normalize_key(key), normalize_key(desination))
77
- value = metamorph(value) if evaluate?
78
- value
79
- end
80
-
81
- def self.move_blocking(key, desination)
82
- value = brpoplpush(normalize_key(key), normalize_key(desination))
83
- value = metamorph(value) if evaluate?
84
- value
85
- end
86
-
87
- def self.destroy(key, count, value)
88
- client.lrem(normalize_key(key), count, value)
89
- end
90
-
91
- def self.destroy_first(key, limit = 1)
92
- client.ltrim(normalize_key(key), limit, -1)
93
- end
94
-
95
- def self.destroy_last(key, limit = 1)
96
- client.ltrim(normalize_key(key), 0, -(limit + 1))
97
- end
98
-
99
- def self.destroy_except(key, start, finish)
100
- client.ltrim(normalize_key(key), (start - 1), (finish - 1))
101
- end
102
-
103
- def self.destroy_all(key)
104
- client.ltrim(normalize_key(key), -1, 0)
105
- end
106
-
107
- def self.pop(key, order = :prepend)
108
- value = append?(order) ? client.rpop(key) : client.lpop(key)
109
- value = metamorph(value) if evaluate?
110
- value
111
- end
112
-
113
- def self.pop_blocking(keys, opts = {})
114
- timeout = opts[:timeout] || 0
115
- value = if append?(opts[:order] || :prepend)
116
- client.brpop(keys, timeout)
117
- else
118
- client.blpop(keys, timeout)
119
- end
120
-
121
- value = metamorph(value) if evaluate?
122
- value
123
- end
124
-
125
129
  end